Skip to contentSkip to conversation

block: zoned: fix harmless maybe-uninitialized warning

PATCH In review Arnd Bergmann 5 participants 5 messages Oct 21, 2016 – Oct 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: zoned: fix harmless maybe-uninitialized warning

The blkdev_report_zones produces a harmless warning when -Wmaybe-uninitialized is set, after gcc gets a little confused about the multiple 'goto' here:

block/blk-zoned.c: In function 'blkdev_report_zones':
block/blk-zoned.c:188:13: error: 'nz' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Moving the assignment to nr_zones makes this a little simpler while also avoiding the warning reliably. I'm removing the extraneous initialization of 'int ret' in the same patch, as that is semi-related and could cause an uninitialized use of that variable to not produce a warning.

Fixes 6a0cb1bc106f ("block: Implement support for zoned block devices")
---
 block/blk-zoned.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
block/blk-zoned.c +2 -4
index 667f95d86695..472211fa183a 100644
@@ -80,7 +80,7 @@ int blkdev_report_zones(struct block_device *bdev,
 	unsigned int i, n, nz;
 	unsigned int ofst;
 	void *addr;
-	int ret = 0;
+	int ret;
 
 	if (!q)
 		return -ENXIO;
@@ -179,14 +179,12 @@ int blkdev_report_zones(struct block_device *bdev,
 
 	}
 
+	*nr_zones = nz;
 out:
 	bio_for_each_segment_all(bv, bio, i)
 		__free_page(bv->bv_page);
 	bio_put(bio);
 
-	if (ret == 0)
-		*nr_zones = nz;
-
 	return ret;
 }
 EXPORT_SYMBOL_GPL(blkdev_report_zones);
Signature · 1 line
2.9.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Arnd Bergmann

The blkdev_report_zones produces a harmless warning when -Wmaybe-uninitialized is set, after gcc gets a little confused about the multiple 'goto' here:

block/blk-zoned.c: In function 'blkdev_report_zones':
block/blk-zoned.c:188:13: error: 'nz' may be used uninitialized in this f=

unction [-Werror=3Dmaybe-uninitialized]

Quoted 43 lines

Moving the assignment to nr_zones makes this a little simpler while also avoiding the warning reliably. I'm removing the extraneous initialization of 'int ret' in the same patch, as that is semi-related and could cause an uninitialized use of that variable to not produce a warning.

Fixes 6a0cb1bc106f ("block: Implement support for zoned block devices")
---
 block/blk-zoned.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
block/blk-zoned.c +2 -5
index 667f95d86695..472211fa183a 100644
@@ -80,7 +80,7 @@ int blkdev_report_zones(struct block_device *bdev,
        unsigned int i, n, nz;
        unsigned int ofst;
        void *addr;
-       int ret =3D 0;
+       int ret;
 
        if (!q)
                return -ENXIO;
@@ -179,14 +179,12 @@ int blkdev_report_zones(struct block_device *bdev,
 
        }
 
+       *nr_zones =3D nz;
 out:
        bio_for_each_segment_all(bv, bio, i)
                __free_page(bv->bv_page);
        bio_put(bio);
 
-       if (ret =3D=3D 0)
-               *nr_zones =3D nz;
-
        return ret;
 }
 EXPORT_SYMBOL_GPL(blkdev_report_zones);
--
Quoted 1 line

2.9.0

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to [email protected]
More majordomo info at https://urldefense.proofpoint.com/v2/url?u=3Dhttp=

-3A__vger.kernel.org_majordomo-2Dinfo.html&d=3DDQIBAg&c=3DIGDlg0lD0b-nebmJJ= 0Kp8A&r=3DWg5NqlNlVTT7Ugl8V50qIHLe856QW0qfG3WVYGOrWzA&m=3DRyRS1pzTGdFENUb0P= bQRSMAhvMgZx_dBftw2khYVIXU&s=3Dp9SYS2a__p_YHv8FoZVz9kuTQQ7LIZBVKCkZuQgR0cs&= e=3D

--=20
Shaun Tancheff

Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

The blkdev_report_zones produces a harmless warning when -Wmaybe-uninitialized is set, after gcc gets a little confused about the multiple 'goto' here:
=

block/blk-zoned.c: In function 'blkdev_report_zones':
block/blk-zoned.c:188:13: error: 'nz' may be used uninitialized in this f=

unction [-Werror=3Dmaybe-uninitialized]

Quoted 46 lines

=

Moving the assignment to nr_zones makes this a little simpler while also avoiding the warning reliably. I'm removing the extraneous initialization of 'int ret' in the same patch, as that is semi-related and could cause an uninitialized use of that variable to not produce a warning.
=

Fixes 6a0cb1bc106f ("block: Implement support for zoned block devices")
---
 block/blk-zoned.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

=

block/blk-zoned.c +1 -1
index 667f95d86695..472211fa183a 100644
@@ -80,7 +80,7 @@ int blkdev_report_zones(struct block_device *bdev,
 	unsigned int i, n, nz;
 	unsigned int ofst;
 	void *addr;
-	int ret =3D 0;
+	int ret;
 =
 
 	if (!q)
block/blk-zoned.c +1 -3
 		return -ENXIO;
@@ -179,14 +179,12 @@ int blkdev_report_zones(struct block_device *bdev,
 =
 
 	}
 =
 
+	*nr_zones =3D nz;
 out:
 	bio_for_each_segment_all(bv, bio, i)
 		__free_page(bv->bv_page);
 	bio_put(bio);
 =
 
-	if (ret =3D=3D 0)
-		*nr_zones =3D nz;
-
Quoted 3 lines

return ret;
}
EXPORT_SYMBOL_GPL(blkdev_report_zones);

-- =

Damien Le Moal, Ph.D.
Sr. Manager, System Software Research Group,
Western Digital Corporation
[email protected]
(+81) 0466-98-3593 (ext. 513593)
1 kirihara-cho, Fujisawa,
Kanagawa, 252-0888 Japan
www.wdc.com, www.hgst.com
Western Digital Corporation (and its subsidiaries) E-mail Confidentiality N= otice & Disclaimer:

This e-mail and any files transmitted with it may contain confidential or l= egally privileged information of WDC and/or its affiliates, and are intende= d solely for the use of the individual or entity to which they are addresse= d. If you are not the intended recipient, any disclosure, copying, distribu= tion or any action taken or omitted to be taken in reliance on it, is prohi= bited. If you have received this e-mail in error, please notify the sender = immediately and delete the e-mail in its entirety from your system.

#3 lore raw
In reply to Arnd Bergmann
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnd" == Arnd Bergmann <[email protected]> writes:

Arnd> The blkdev_report_zones produces a harmless warning when Arnd> -Wmaybe-uninitialized is set, after gcc gets a little confused Arnd> about the multiple 'goto' here:

Arnd> block/blk-zoned.c: In function 'blkdev_report_zones':
Arnd> block/blk-zoned.c:188:13: error: 'nz' may be used uninitialized in Arnd> this function [-Werror=maybe-uninitialized]

Arnd> Moving the assignment to nr_zones makes this a little simpler Arnd> while also avoiding the warning reliably. I'm removing the Arnd> extraneous initialization of 'int ret' in the same patch, as that Arnd> is semi-related and could cause an uninitialized use of that Arnd> variable to not produce a warning.

Jens: Are you picking up Arnd's two fixes for the zoned code?

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
maintainer
#4 lore raw
Quoted 10 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnd" == Arnd Bergmann <[email protected]> writes:

Arnd> The blkdev_report_zones produces a harmless warning when Arnd> -Wmaybe-uninitialized is set, after gcc gets a little confused Arnd> about the multiple 'goto' here:

Arnd> block/blk-zoned.c: In function 'blkdev_report_zones':
Arnd> block/blk-zoned.c:188:13: error: 'nz' may be used uninitialized in Arnd> this function [-Werror=maybe-uninitialized]

Quoted 7 lines

Arnd> Moving the assignment to nr_zones makes this a little simpler Arnd> while also avoiding the warning reliably. I'm removing the Arnd> extraneous initialization of 'int ret' in the same patch, as that Arnd> is semi-related and could cause an uninitialized use of that Arnd> variable to not produce a warning.

Jens: Are you picking up Arnd's two fixes for the zoned code?

Yep, adding them now. Thanks Arnd.

Signature · 1 line
Jens Axboe