mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dm dust: Convert an 'else if' into an 'else' in dust_map
@ 2019-04-30  2:10 Nathan Chancellor
  2019-04-30 22:31 ` Nick Desaulniers
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2019-04-30  2:10 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer
  Cc: dm-devel, linux-kernel, clang-built-linux, Nick Desaulniers,
	Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/md/dm-dust.c:216:11: warning: variable 'ret' is used
uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]
        else if (bio_data_dir(bio) == WRITE)
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bio.h:69:2: note: expanded from macro 'bio_data_dir'
        (op_is_write(bio_op(bio)) ? WRITE : READ)
        ^
drivers/md/dm-dust.c:219:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/md/dm-dust.c:216:7: note: remove the 'if' if its condition is
always true
        else if (bio_data_dir(bio) == WRITE)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/md/dm-dust.c:209:9: note: initialize the variable 'ret' to
silence this warning
        int ret;
               ^
                = 0
1 warning generated.

It isn't wrong; however, bio_data_dir will only ever return READ and
WRITE so the second 'else if' can really become an 'else' to silence
this warning and not change the final meaning of the code.

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

diff --git a/drivers/md/dm-dust.c b/drivers/md/dm-dust.c
index 997830984893..5baeb56679ed 100644
--- a/drivers/md/dm-dust.c
+++ b/drivers/md/dm-dust.c
@@ -213,7 +213,7 @@ static int dust_map(struct dm_target *ti, struct bio *bio)
 
 	if (bio_data_dir(bio) == READ)
 		ret = dust_map_read(dd, bio->bi_iter.bi_sector, dd->fail_read_on_bb);
-	else if (bio_data_dir(bio) == WRITE)
+	else
 		ret = dust_map_write(dd, bio->bi_iter.bi_sector, dd->fail_read_on_bb);
 
 	return ret;
-- 
2.21.0


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

* Re: [PATCH] dm dust: Convert an 'else if' into an 'else' in dust_map
  2019-04-30  2:10 [PATCH] dm dust: Convert an 'else if' into an 'else' in dust_map Nathan Chancellor
@ 2019-04-30 22:31 ` Nick Desaulniers
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Desaulniers @ 2019-04-30 22:31 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Alasdair Kergon, Mike Snitzer, dm-devel, LKML, clang-built-linux

On Mon, Apr 29, 2019 at 7:10 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> When building with -Wsometimes-uninitialized, Clang warns:
>
> drivers/md/dm-dust.c:216:11: warning: variable 'ret' is used
> uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
>         else if (bio_data_dir(bio) == WRITE)
>                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/bio.h:69:2: note: expanded from macro 'bio_data_dir'
>         (op_is_write(bio_op(bio)) ? WRITE : READ)
>         ^
> drivers/md/dm-dust.c:219:9: note: uninitialized use occurs here
>         return ret;
>                ^~~
> drivers/md/dm-dust.c:216:7: note: remove the 'if' if its condition is
> always true
>         else if (bio_data_dir(bio) == WRITE)
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/md/dm-dust.c:209:9: note: initialize the variable 'ret' to
> silence this warning
>         int ret;
>                ^
>                 = 0
> 1 warning generated.
>
> It isn't wrong; however, bio_data_dir will only ever return READ and
> WRITE so the second 'else if' can really become an 'else' to silence
> this warning and not change the final meaning of the code.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/462
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  drivers/md/dm-dust.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/md/dm-dust.c b/drivers/md/dm-dust.c
> index 997830984893..5baeb56679ed 100644
> --- a/drivers/md/dm-dust.c
> +++ b/drivers/md/dm-dust.c
> @@ -213,7 +213,7 @@ static int dust_map(struct dm_target *ti, struct bio *bio)
>
>         if (bio_data_dir(bio) == READ)
>                 ret = dust_map_read(dd, bio->bi_iter.bi_sector, dd->fail_read_on_bb);
> -       else if (bio_data_dir(bio) == WRITE)
> +       else
>                 ret = dust_map_write(dd, bio->bi_iter.bi_sector, dd->fail_read_on_bb);
>
>         return ret;
> --
> 2.21.0
>

Thanks for the patch.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2019-04-30 22:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-30  2:10 [PATCH] dm dust: Convert an 'else if' into an 'else' in dust_map Nathan Chancellor
2019-04-30 22:31 ` Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®