[PATCH 2/2] btrfs: convert to mutex guard in btrfs_ioctl_balance_progress()

From: Yangtao Li
Date: Wed Apr 09 2025 - 08:40:33 EST


To simplify handling, use the guard helper to let the compiler care for
unlocking.

Signed-off-by: Yangtao Li <frank.li@xxxxxxxx>
---
fs/btrfs/ioctl.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 7cec105a4cb0..1d8c28aa84d2 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3620,22 +3620,19 @@ static long btrfs_ioctl_balance_progress(struct btrfs_fs_info *fs_info,
void __user *arg)
{
struct btrfs_ioctl_balance_args *bargs;
- int ret = 0;
+ int ret;

if (!capable(CAP_SYS_ADMIN))
return -EPERM;

- mutex_lock(&fs_info->balance_mutex);
- if (!fs_info->balance_ctl) {
- ret = -ENOTCONN;
- goto out;
- }
+ guard(mutex)(&fs_info->balance_mutex);
+
+ if (!fs_info->balance_ctl)
+ return -ENOTCONN;

bargs = kzalloc(sizeof(*bargs), GFP_KERNEL);
- if (!bargs) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!bargs)
+ return -ENOMEM;

btrfs_update_ioctl_balance_args(fs_info, bargs);

@@ -3643,8 +3640,7 @@ static long btrfs_ioctl_balance_progress(struct btrfs_fs_info *fs_info,
ret = -EFAULT;

kfree(bargs);
-out:
- mutex_unlock(&fs_info->balance_mutex);
+
return ret;
}

--
2.39.0