btrfs: open code rcu_string_free() and remove it
authorDavid Sterba <dsterba@suse.com>
Mon, 9 Jun 2025 17:09:21 +0000 (19:09 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:56:38 +0000 (23:56 +0200)
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 <neelx@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/rcu-string.h
fs/btrfs/volumes.c

index 1c2d7cb1fe6f635bada8a97ae1f3b16a5d67e338..7f35cf75b50ff3d5b551fd43655e7305d5ee994e 100644 (file)
@@ -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__);       \
index 1535a425e8f9ac633c015fc7764edcef42090cb7..afbd10bb627582ed99bd0b17a49a4b53fffe2a9a 100644 (file)
@@ -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--;