2022-01-22 01:35:02

by Tom Rix

[permalink] [raw]
Subject: [PATCH] btrfs: initialize variable cancel

From: Tom Rix <[email protected]>

Clang static analysis reports this problem
ioctl.c:3333:8: warning: 3rd function call argument is an
uninitialized value
ret = exclop_start_or_cancel_reloc(fs_info,

cancel is only set in one branch of an if-check and is
always used. So initialize to false.

Fixes: 1a15eb724aae ("btrfs: use btrfs_get_dev_args_from_path in dev removal ioctls")
Signed-off-by: Tom Rix <[email protected]>
---
fs/btrfs/ioctl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 190ad8af4f45a..26e82379747f8 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3308,7 +3308,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
struct block_device *bdev = NULL;
fmode_t mode;
int ret;
- bool cancel;
+ bool cancel = false;

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


2022-01-22 01:55:09

by Filipe Manana

[permalink] [raw]
Subject: Re: [PATCH] btrfs: initialize variable cancel

On Fri, Jan 21, 2022 at 05:45:22AM -0800, [email protected] wrote:
> From: Tom Rix <[email protected]>
>
> Clang static analysis reports this problem
> ioctl.c:3333:8: warning: 3rd function call argument is an
> uninitialized value
> ret = exclop_start_or_cancel_reloc(fs_info,
>
> cancel is only set in one branch of an if-check and is
> always used. So initialize to false.
>
> Fixes: 1a15eb724aae ("btrfs: use btrfs_get_dev_args_from_path in dev removal ioctls")
> Signed-off-by: Tom Rix <[email protected]>

Reviewed-by: Filipe Manana <[email protected]>

Could use a more precise subject like for example:

"btrfs: fix use of uninitialized variable at rm device ioctl"

Anyway, it looks good.
Thanks.

> ---
> fs/btrfs/ioctl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 190ad8af4f45a..26e82379747f8 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -3308,7 +3308,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
> struct block_device *bdev = NULL;
> fmode_t mode;
> int ret;
> - bool cancel;
> + bool cancel = false;
>
> if (!capable(CAP_SYS_ADMIN))
> return -EPERM;
> --
> 2.26.3
>

2022-01-22 09:41:28

by Anand Jain

[permalink] [raw]
Subject: Re: [PATCH] btrfs: initialize variable cancel



On 21/01/2022 21:45, [email protected] wrote:
> From: Tom Rix <[email protected]>
>
> Clang static analysis reports this problem
> ioctl.c:3333:8: warning: 3rd function call argument is an
> uninitialized value
> ret = exclop_start_or_cancel_reloc(fs_info,
>
> cancel is only set in one branch of an if-check and is
> always used. So initialize to false.
>
> Fixes: 1a15eb724aae ("btrfs: use btrfs_get_dev_args_from_path in dev removal ioctls")
> Signed-off-by: Tom Rix <[email protected]>
> ---
> fs/btrfs/ioctl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 190ad8af4f45a..26e82379747f8 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -3308,7 +3308,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
> struct block_device *bdev = NULL;
> fmode_t mode;
> int ret;
> - bool cancel;
> + bool cancel = false;


Reviewed-by: Anand Jain <[email protected]>

Thanks,
Anand

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

2022-01-25 08:25:28

by David Sterba

[permalink] [raw]
Subject: Re: [PATCH] btrfs: initialize variable cancel

On Fri, Jan 21, 2022 at 05:45:22AM -0800, [email protected] wrote:
> From: Tom Rix <[email protected]>
>
> Clang static analysis reports this problem
> ioctl.c:3333:8: warning: 3rd function call argument is an
> uninitialized value
> ret = exclop_start_or_cancel_reloc(fs_info,
>
> cancel is only set in one branch of an if-check and is
> always used. So initialize to false.
>
> Fixes: 1a15eb724aae ("btrfs: use btrfs_get_dev_args_from_path in dev removal ioctls")
> Signed-off-by: Tom Rix <[email protected]>

Added to misc-next, with the updted subject line, thanks.