Skip to contentSkip to conversation

dm dust: Convert an 'else if' into an 'else' in dust_map

PATCH In review Nathan Chancellor 2 participants 2 messages Apr 30, 2019 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm dust: Convert an 'else if' into an 'else' in dust_map

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.

---
 drivers/md/dm-dust.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-dust.c +1 -1
index 997830984893..5baeb56679ed 100644
@@ -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;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines · 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.

---
 drivers/md/dm-dust.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-dust.c +1 -2
index 997830984893..5baeb56679ed 100644
@@ -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;
--
Quoted 2 lines

2.21.0

Thanks for the patch.

Signature · 2 lines
Thanks,
~Nick Desaulniers