From: David Sterba Date: Mon, 9 Jun 2025 17:09:21 +0000 (+0200) Subject: btrfs: open code rcu_string_free() and remove it X-Git-Tag: block-6.17-20250808~77^2~121 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=d1d1c854270ae21c2c770ac42591558b6511578e;p=linux-block.git btrfs: open code rcu_string_free() and remove it The helper is trivial and we can simply use kfree_rcu() if needed. In our case it's just one place where we rename a device in device_list_add() and the old name can still be used until the end of the RCU grace period. The other case is freeing a device and there nothing should reach the device, so we can use plain kfree(). Reviewed-by: Daniel Vacek Signed-off-by: David Sterba --- diff --git a/fs/btrfs/rcu-string.h b/fs/btrfs/rcu-string.h index 1c2d7cb1fe6f..7f35cf75b50f 100644 --- a/fs/btrfs/rcu-string.h +++ b/fs/btrfs/rcu-string.h @@ -32,12 +32,6 @@ static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask) return ret; } -static inline void rcu_string_free(struct rcu_string *str) -{ - if (str) - kfree_rcu(str, rcu); -} - #define printk_in_rcu(fmt, ...) do { \ rcu_read_lock(); \ printk(fmt, __VA_ARGS__); \ diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1535a425e8f9..afbd10bb6275 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -403,7 +403,8 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid) static void btrfs_free_device(struct btrfs_device *device) { WARN_ON(!list_empty(&device->post_commit_list)); - rcu_string_free(device->name); + /* No need to call kfree_rcu(), nothing is reading the device name. */ + kfree(device->name); btrfs_extent_io_tree_release(&device->alloc_state); btrfs_destroy_dev_zone_info(device); kfree(device); @@ -962,7 +963,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, mutex_unlock(&fs_devices->device_list_mutex); return ERR_PTR(-ENOMEM); } - rcu_string_free(device->name); + kfree_rcu(device->name, rcu); rcu_assign_pointer(device->name, name); if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)) { fs_devices->missing_devices--;