All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: initialize variable cancel
@ 2022-01-21 13:45 trix
  2022-01-21 15:40 ` Filipe Manana
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: trix @ 2022-01-21 13:45 UTC (permalink / raw)
  To: clm, josef, dsterba, nathan, ndesaulniers, anand.jain
  Cc: linux-btrfs, linux-kernel, llvm, Tom Rix

From: Tom Rix <trix@redhat.com>

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 <trix@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] btrfs: initialize variable cancel
  2022-01-21 13:45 [PATCH] btrfs: initialize variable cancel trix
@ 2022-01-21 15:40 ` Filipe Manana
  2022-01-21 21:50 ` Anand Jain
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Filipe Manana @ 2022-01-21 15:40 UTC (permalink / raw)
  To: trix
  Cc: clm, josef, dsterba, nathan, ndesaulniers, anand.jain,
	linux-btrfs, linux-kernel, llvm

On Fri, Jan 21, 2022 at 05:45:22AM -0800, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> 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 <trix@redhat.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

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
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] btrfs: initialize variable cancel
  2022-01-21 13:45 [PATCH] btrfs: initialize variable cancel trix
  2022-01-21 15:40 ` Filipe Manana
@ 2022-01-21 21:50 ` Anand Jain
  2022-01-24 19:49 ` David Sterba
  2022-01-25  5:04 ` Wang Yugui
  3 siblings, 0 replies; 7+ messages in thread
From: Anand Jain @ 2022-01-21 21:50 UTC (permalink / raw)
  To: trix, clm, josef, dsterba, nathan, ndesaulniers
  Cc: linux-btrfs, linux-kernel, llvm



On 21/01/2022 21:45, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> 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 <trix@redhat.com>
> ---
>   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 <anand.jain@oracle.com>

Thanks,
Anand

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] btrfs: initialize variable cancel
  2022-01-21 13:45 [PATCH] btrfs: initialize variable cancel trix
  2022-01-21 15:40 ` Filipe Manana
  2022-01-21 21:50 ` Anand Jain
@ 2022-01-24 19:49 ` David Sterba
  2022-01-25  5:04 ` Wang Yugui
  3 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2022-01-24 19:49 UTC (permalink / raw)
  To: trix
  Cc: clm, josef, dsterba, nathan, ndesaulniers, anand.jain,
	linux-btrfs, linux-kernel, llvm

On Fri, Jan 21, 2022 at 05:45:22AM -0800, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> 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 <trix@redhat.com>

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] btrfs: initialize variable cancel
  2022-01-21 13:45 [PATCH] btrfs: initialize variable cancel trix
                   ` (2 preceding siblings ...)
  2022-01-24 19:49 ` David Sterba
@ 2022-01-25  5:04 ` Wang Yugui
  2022-01-25  8:30   ` Johannes Thumshirn
  3 siblings, 1 reply; 7+ messages in thread
From: Wang Yugui @ 2022-01-25  5:04 UTC (permalink / raw)
  To: trix; +Cc: linux-btrfs

Hi,

Mabye we should enable '-Wmaybe-uninitialized' for btrfs 'make W=1'.

There is another warning  reproted by '-Wmaybe-uninitialized' 
in btrfs misc-next.

fs/btrfs/zoned.c:273:28: warning: ‘zno’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   memcpy(zinfo->zone_cache + zno, zones,
                            ^

diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index cec88a6..f1052ce 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -2,6 +2,7 @@
 
 # Subset of W=1 warnings
 subdir-ccflags-y += -Wextra -Wunused -Wno-unused-parameter
+subdir-ccflags-y += -Wmaybe-uninitialized
 subdir-ccflags-y += -Wmissing-declarations
 subdir-ccflags-y += -Wmissing-format-attribute
 subdir-ccflags-y += -Wmissing-prototypes

Best Regards
Wang Yugui (wangyugui@e16-tech.com)
2022/01/25

> From: Tom Rix <trix@redhat.com>
> 
> 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 <trix@redhat.com>
> ---
>  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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] btrfs: initialize variable cancel
  2022-01-25  5:04 ` Wang Yugui
@ 2022-01-25  8:30   ` Johannes Thumshirn
  2022-01-25 13:27     ` David Sterba
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Thumshirn @ 2022-01-25  8:30 UTC (permalink / raw)
  To: wangyugui, trix; +Cc: linux-btrfs

On Tue, 2022-01-25 at 13:04 +0800, Wang Yugui wrote:
> Hi,
> 
> Mabye we should enable '-Wmaybe-uninitialized' for btrfs 'make W=1'.
> 
> There is another warning  reproted by '-Wmaybe-uninitialized' 
> in btrfs misc-next.
> 
> fs/btrfs/zoned.c:273:28: warning: ‘zno’ may be used uninitialized in
> this function [-Wmaybe-uninitialized]
>    memcpy(zinfo->zone_cache + zno, zones,
>                             ^


Isn't that one a false positive?

      u32 zno;                                                        

[...]                                                                 
        /* Check cache */                                             
        if (zinfo->zone_cache) {                                      
                unsigned int i;                                       
                                                                               
                ASSERT(IS_ALIGNED(pos, zinfo->zone_size));            
                zno = pos >> zinfo->zone_size_shift;                  
[...]
        }                                                             
                                                                               
[...]    
                                                                      
        /* Populate cache */                                          
        if (zinfo->zone_cache)                                        
                memcpy(zinfo->zone_cache + zno, zones,                
                       sizeof(*zinfo->zone_cache) * *nr_zones);       
                                    

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] btrfs: initialize variable cancel
  2022-01-25  8:30   ` Johannes Thumshirn
@ 2022-01-25 13:27     ` David Sterba
  0 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2022-01-25 13:27 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: wangyugui, trix, linux-btrfs

On Tue, Jan 25, 2022 at 08:30:34AM +0000, Johannes Thumshirn wrote:
> On Tue, 2022-01-25 at 13:04 +0800, Wang Yugui wrote:
> > Hi,
> > 
> > Mabye we should enable '-Wmaybe-uninitialized' for btrfs 'make W=1'.
> > 
> > There is another warning  reproted by '-Wmaybe-uninitialized' 
> > in btrfs misc-next.
> > 
> > fs/btrfs/zoned.c:273:28: warning: ‘zno’ may be used uninitialized in
> > this function [-Wmaybe-uninitialized]
> >    memcpy(zinfo->zone_cache + zno, zones,
> >                             ^
> 
> 
> Isn't that one a false positive?
> 
>       u32 zno;                                                        
> 
> [...]                                                                 
>         /* Check cache */                                             
>         if (zinfo->zone_cache) {                                      
>                 unsigned int i;                                       
>                                                                                
>                 ASSERT(IS_ALIGNED(pos, zinfo->zone_size));            
>                 zno = pos >> zinfo->zone_size_shift;                  
> [...]
>         }                                                             
>                                                                                
> [...]    
>                                                                       
>         /* Populate cache */                                          
>         if (zinfo->zone_cache)                                        
>                 memcpy(zinfo->zone_cache + zno, zones,                
>                        sizeof(*zinfo->zone_cache) * *nr_zones);       
>                                     

Yeah looks like a false positive, maybe it can't reason that
zinfo->zone_cache won't change between the conditions from NULL to valid
pointer.

And as there are other warnings in sb_zone_number we can't set
-Wmaybe-uninitialized by default. I think this could be even more
problematic with older compiler versions.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-01-25 13:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21 13:45 [PATCH] btrfs: initialize variable cancel trix
2022-01-21 15:40 ` Filipe Manana
2022-01-21 21:50 ` Anand Jain
2022-01-24 19:49 ` David Sterba
2022-01-25  5:04 ` Wang Yugui
2022-01-25  8:30   ` Johannes Thumshirn
2022-01-25 13:27     ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.