diff mbox series

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

Message ID 20250409125724.145597-2-frank.li@vivo.com (mailing list archive)
State New
Headers show
Series [1/2] btrfs: convert to spinlock guards in btrfs_update_ioctl_balance_args() | expand

Commit Message

李扬韬 April 9, 2025, 12:57 p.m. UTC
To simplify handling, use the guard helper to let the compiler care for
unlocking.

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

Comments

kernel test robot April 10, 2025, 2:45 p.m. UTC | #1
Hi Yangtao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on linus/master v6.15-rc1 next-20250410]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yangtao-Li/btrfs-convert-to-mutex-guard-in-btrfs_ioctl_balance_progress/20250409-204204
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/20250409125724.145597-2-frank.li%40vivo.com
patch subject: [PATCH 2/2] btrfs: convert to mutex guard in btrfs_ioctl_balance_progress()
config: arm-randconfig-001-20250410 (https://download.01.org/0day-ci/archive/20250410/202504102206.gpAU9chA-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250410/202504102206.gpAU9chA-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504102206.gpAU9chA-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> fs/btrfs/ioctl.c:3639:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    3639 |         if (copy_to_user(arg, bargs, sizeof(*bargs)))
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/btrfs/ioctl.c:3644:9: note: uninitialized use occurs here
    3644 |         return ret;
         |                ^~~
   fs/btrfs/ioctl.c:3639:2: note: remove the 'if' if its condition is always true
    3639 |         if (copy_to_user(arg, bargs, sizeof(*bargs)))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3640 |                 ret = -EFAULT;
   fs/btrfs/ioctl.c:3623:9: note: initialize the variable 'ret' to silence this warning
    3623 |         int ret;
         |                ^
         |                 = 0
   1 warning generated.


vim +3639 fs/btrfs/ioctl.c

837d5b6e46d1a4 Ilya Dryomov 2012-01-16  3618  
2ff7e61e0d30ff Jeff Mahoney 2016-06-22  3619  static long btrfs_ioctl_balance_progress(struct btrfs_fs_info *fs_info,
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3620  					 void __user *arg)
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3621  {
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3622  	struct btrfs_ioctl_balance_args *bargs;
68395a7bf00486 Yangtao Li   2025-04-09  3623  	int ret;
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3624  
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3625  	if (!capable(CAP_SYS_ADMIN))
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3626  		return -EPERM;
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3627  
68395a7bf00486 Yangtao Li   2025-04-09  3628  	guard(mutex)(&fs_info->balance_mutex);
68395a7bf00486 Yangtao Li   2025-04-09  3629  
68395a7bf00486 Yangtao Li   2025-04-09  3630  	if (!fs_info->balance_ctl)
68395a7bf00486 Yangtao Li   2025-04-09  3631  		return -ENOTCONN;
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3632  
8d2db7855e7b65 David Sterba 2015-11-04  3633  	bargs = kzalloc(sizeof(*bargs), GFP_KERNEL);
68395a7bf00486 Yangtao Li   2025-04-09  3634  	if (!bargs)
68395a7bf00486 Yangtao Li   2025-04-09  3635  		return -ENOMEM;
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3636  
008ef0969dd966 David Sterba 2018-03-21  3637  	btrfs_update_ioctl_balance_args(fs_info, bargs);
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3638  
19a39dce3b9bf0 Ilya Dryomov 2012-01-16 @3639  	if (copy_to_user(arg, bargs, sizeof(*bargs)))
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3640  		ret = -EFAULT;
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3641  
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3642  	kfree(bargs);
68395a7bf00486 Yangtao Li   2025-04-09  3643  
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3644  	return ret;
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3645  }
19a39dce3b9bf0 Ilya Dryomov 2012-01-16  3646
diff mbox series

Patch

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;
 }