linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bcache: Zero initialize bucket in bch_allocator_thread
@ 2019-03-07 22:10 Nathan Chancellor
  2019-03-08  2:10 ` Coly Li
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2019-03-07 22:10 UTC (permalink / raw)
  To: Coly Li, Kent Overstreet
  Cc: linux-bcache, linux-kernel, clang-built-linux, Nick Desaulniers,
	Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/md/bcache/alloc.c:333:4: warning: variable 'bucket' is used
uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]

fifo_pop expands to a conditional depending on '!fifo_empty(...)', which
is the same condition as the while loop. It seems Clang can't piece
together that this condition will never been false as long as we are in
the while loop because they are the same condition. It's easy enough to
silence this warning by just explicitly zero initializing bucket.

Link: https://github.com/ClangBuiltLinux/linux/issues/396
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 drivers/md/bcache/alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
index 5002838ea476..c72094901ac6 100644
--- a/drivers/md/bcache/alloc.c
+++ b/drivers/md/bcache/alloc.c
@@ -328,7 +328,7 @@ static int bch_allocator_thread(void *arg)
 		 * the free list:
 		 */
 		while (!fifo_empty(&ca->free_inc)) {
-			long bucket;
+			long bucket = 0;
 
 			fifo_pop(&ca->free_inc, bucket);
 
-- 
2.21.0


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

* Re: [PATCH] bcache: Zero initialize bucket in bch_allocator_thread
  2019-03-07 22:10 [PATCH] bcache: Zero initialize bucket in bch_allocator_thread Nathan Chancellor
@ 2019-03-08  2:10 ` Coly Li
  2019-03-22 14:36   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Coly Li @ 2019-03-08  2:10 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Kent Overstreet, linux-bcache, linux-kernel, clang-built-linux,
	Nick Desaulniers

On 2019/3/8 6:10 上午, Nathan Chancellor wrote:
> When building with -Wsometimes-uninitialized, Clang warns:
> 
> drivers/md/bcache/alloc.c:333:4: warning: variable 'bucket' is used
> uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
> 
> fifo_pop expands to a conditional depending on '!fifo_empty(...)', which
> is the same condition as the while loop. It seems Clang can't piece
> together that this condition will never been false as long as we are in
> the while loop because they are the same condition. It's easy enough to
> silence this warning by just explicitly zero initializing bucket.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/396
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Hi Nathan,

Nice catch, I will add it to my for-test. Thanks.

Coly Li

> ---
>  drivers/md/bcache/alloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
> index 5002838ea476..c72094901ac6 100644
> --- a/drivers/md/bcache/alloc.c
> +++ b/drivers/md/bcache/alloc.c
> @@ -328,7 +328,7 @@ static int bch_allocator_thread(void *arg)
>  		 * the free list:
>  		 */
>  		while (!fifo_empty(&ca->free_inc)) {
> -			long bucket;
> +			long bucket = 0;
>  
>  			fifo_pop(&ca->free_inc, bucket);
>  
> 


-- 

Coly Li

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

* Re: [PATCH] bcache: Zero initialize bucket in bch_allocator_thread
  2019-03-08  2:10 ` Coly Li
@ 2019-03-22 14:36   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:36 UTC (permalink / raw)
  To: Coly Li
  Cc: Nathan Chancellor, Kent Overstreet, linux-bcache,
	Linux Kernel Mailing List, clang-built-linux, Nick Desaulniers

On Fri, Mar 8, 2019 at 3:11 AM Coly Li <colyli@suse.de> wrote:
> On 2019/3/8 6:10 上午, Nathan Chancellor wrote:
> > When building with -Wsometimes-uninitialized, Clang warns:
> >
> > drivers/md/bcache/alloc.c:333:4: warning: variable 'bucket' is used
> > uninitialized whenever 'if' condition is false
> > [-Wsometimes-uninitialized]
> >
> > fifo_pop expands to a conditional depending on '!fifo_empty(...)', which
> > is the same condition as the while loop. It seems Clang can't piece
> > together that this condition will never been false as long as we are in
> > the while loop because they are the same condition. It's easy enough to
> > silence this warning by just explicitly zero initializing bucket.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/396
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
>
> Hi Nathan,
>
> Nice catch, I will add it to my for-test. Thanks.

I saw the same warning but came up with a nicer (IMHO) fix, see
https://lore.kernel.org/lkml/20190322143507.1256436-1-arnd@arndb.de/T/#u

        Arnd

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

end of thread, other threads:[~2019-03-22 14:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 22:10 [PATCH] bcache: Zero initialize bucket in bch_allocator_thread Nathan Chancellor
2019-03-08  2:10 ` Coly Li
2019-03-22 14:36   ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).