[v3,06/10] btrfs: convert to kobject_del_and_put()
Commit Message
Use kobject_del_and_put() to simplify code.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Yangtao Li <frank.li@vivo.com>
Acked-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/block-group.c | 5 +----
fs/btrfs/sysfs.c | 38 ++++++++++++--------------------------
2 files changed, 13 insertions(+), 30 deletions(-)
Comments
On 3/23/23 01:59, Yangtao Li wrote:
> Use kobject_del_and_put() to simplify code.
>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> Acked-by: David Sterba <dsterba@suse.com>
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
@@ -1125,10 +1125,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
}
up_write(&block_group->space_info->groups_sem);
clear_incompat_bg_bits(fs_info, block_group->flags);
- if (kobj) {
- kobject_del(kobj);
- kobject_put(kobj);
- }
+ kobject_del_and_put(kobj);
if (block_group->cached == BTRFS_CACHE_STARTED)
btrfs_wait_block_group_cache_done(block_group);
@@ -1390,20 +1390,17 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
{
if (fs_devs->devinfo_kobj) {
- kobject_del(fs_devs->devinfo_kobj);
- kobject_put(fs_devs->devinfo_kobj);
+ kobject_del_and_put(fs_devs->devinfo_kobj);
fs_devs->devinfo_kobj = NULL;
}
if (fs_devs->devices_kobj) {
- kobject_del(fs_devs->devices_kobj);
- kobject_put(fs_devs->devices_kobj);
+ kobject_del_and_put(fs_devs->devices_kobj);
fs_devs->devices_kobj = NULL;
}
if (fs_devs->fsid_kobj.state_initialized) {
- kobject_del(&fs_devs->fsid_kobj);
- kobject_put(&fs_devs->fsid_kobj);
+ kobject_del_and_put(&fs_devs->fsid_kobj);
wait_for_completion(&fs_devs->kobj_unregister);
}
}
@@ -1445,19 +1442,16 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
if (fs_info->space_info_kobj) {
sysfs_remove_files(fs_info->space_info_kobj, allocation_attrs);
- kobject_del(fs_info->space_info_kobj);
- kobject_put(fs_info->space_info_kobj);
+ kobject_del_and_put(fs_info->space_info_kobj);
}
if (fs_info->discard_kobj) {
sysfs_remove_files(fs_info->discard_kobj, discard_attrs);
- kobject_del(fs_info->discard_kobj);
- kobject_put(fs_info->discard_kobj);
+ kobject_del_and_put(fs_info->discard_kobj);
}
#ifdef CONFIG_BTRFS_DEBUG
if (fs_info->debug_kobj) {
sysfs_remove_files(fs_info->debug_kobj, btrfs_debug_mount_attrs);
- kobject_del(fs_info->debug_kobj);
- kobject_put(fs_info->debug_kobj);
+ kobject_del_and_put(fs_info->debug_kobj);
}
#endif
addrm_unknown_feature_attrs(fs_info, false);
@@ -1620,13 +1614,9 @@ void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info)
kobj = space_info->block_group_kobjs[i];
space_info->block_group_kobjs[i] = NULL;
- if (kobj) {
- kobject_del(kobj);
- kobject_put(kobj);
- }
+ kobject_del_and_put(kobj);
}
- kobject_del(&space_info->kobj);
- kobject_put(&space_info->kobj);
+ kobject_del_and_put(&space_info->kobj);
}
static const char *alloc_name(u64 flags)
@@ -1681,8 +1671,7 @@ void btrfs_sysfs_remove_device(struct btrfs_device *device)
sysfs_remove_link(devices_kobj, bdev_kobj(device->bdev)->name);
if (device->devid_kobj.state_initialized) {
- kobject_del(&device->devid_kobj);
- kobject_put(&device->devid_kobj);
+ kobject_del_and_put(&device->devid_kobj);
wait_for_completion(&device->kobj_unregister);
}
}
@@ -2255,8 +2244,7 @@ void btrfs_sysfs_del_qgroups(struct btrfs_fs_info *fs_info)
&fs_info->qgroup_tree, node)
btrfs_sysfs_del_one_qgroup(fs_info, qgroup);
if (fs_info->qgroups_kobj) {
- kobject_del(fs_info->qgroups_kobj);
- kobject_put(fs_info->qgroups_kobj);
+ kobject_del_and_put(fs_info->qgroups_kobj);
fs_info->qgroups_kobj = NULL;
}
}
@@ -2304,10 +2292,8 @@ void btrfs_sysfs_del_one_qgroup(struct btrfs_fs_info *fs_info,
if (test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state))
return;
- if (qgroup->kobj.state_initialized) {
- kobject_del(&qgroup->kobj);
- kobject_put(&qgroup->kobj);
- }
+ if (qgroup->kobj.state_initialized)
+ kobject_del_and_put(&qgroup->kobj);
}
/*