mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] UBI: silence erroneous GCC warning about uninitialized read
@ 2019-07-15 14:55 Ahmad Fatoum
  2019-07-18  6:53 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2019-07-15 14:55 UTC (permalink / raw)
  To: barebox

GCC reports following use of an uninitialized variable:

  ./drivers/mtd/ubi/eba.c: In function 'try_write_vid_and_data':
  ./drivers/mtd/ubi/eba.c:904:9: warning:
    'opnum' may be used uninitialized in this function [-Wmaybe-uninitialized]
       err = ubi_wl_put_peb(ubi, vol_id, lnum, opnum, 0);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is incorrect, because it's only called when err == 0 and opnum
is always initialized if err == 0. Silence the warning by initializing
a variable.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mtd/ubi/eba.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 3aae3029e5b6..cca6ec4ba915 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -865,7 +865,7 @@ static int try_write_vid_and_data(struct ubi_volume *vol, int lnum,
 				  int offset, int len)
 {
 	struct ubi_device *ubi = vol->ubi;
-	int pnum, opnum, err, vol_id = vol->vol_id;
+	int pnum, opnum = -1, err, vol_id = vol->vol_id;
 
 	pnum = ubi_wl_get_peb(ubi);
 	if (pnum < 0) {
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-07-18  6:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-15 14:55 [PATCH] UBI: silence erroneous GCC warning about uninitialized read Ahmad Fatoum
2019-07-18  6:53 ` Sascha Hauer

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