public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: avoid using uninitialized value in from  queue_var_store
@ 2013-04-03 15:30 Arnd Bergmann
  2013-04-03 19:52 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2013-04-03 15:30 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel

As found by gcc-4.8, the QUEUE_SYSFS_BIT_FNS macro creates functions
that use a value generated by queue_var_store independent of whether
that value was set or not.

block/blk-sysfs.c: In function 'queue_store_nonrot':
block/blk-sysfs.c:244:385: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]

Unlike most other such warnings, this one is not a false positive,
writing any non-number string into the sysfs files indeed has
an undefined result, rather than returning an error.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Jens Axboe <jaxboe@fusionio.com>
---
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 6206a93..5efc5a6 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -229,6 +229,8 @@ queue_store_##name(struct request_queue *q, const char *page, size_t count) \
 	unsigned long val;						\
 	ssize_t ret;							\
 	ret = queue_var_store(&val, page, count);			\
+	if (ret < 0)							\
+		 return ret;						\
 	if (neg)							\
 		val = !val;						\
 									\

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

* Re: [PATCH] block: avoid using uninitialized value in from queue_var_store
  2013-04-03 15:30 [PATCH] block: avoid using uninitialized value in from queue_var_store Arnd Bergmann
@ 2013-04-03 19:52 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2013-04-03 19:52 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-kernel@vger.kernel.org

On Wed, Apr 03 2013, Arnd Bergmann wrote:
> As found by gcc-4.8, the QUEUE_SYSFS_BIT_FNS macro creates functions
> that use a value generated by queue_var_store independent of whether
> that value was set or not.
> 
> block/blk-sysfs.c: In function 'queue_store_nonrot':
> block/blk-sysfs.c:244:385: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> Unlike most other such warnings, this one is not a false positive,
> writing any non-number string into the sysfs files indeed has
> an undefined result, rather than returning an error.

Huh indeed, thanks Arnd. Queued up.

-- 
Jens Axboe


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

end of thread, other threads:[~2013-04-03 19:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-03 15:30 [PATCH] block: avoid using uninitialized value in from queue_var_store Arnd Bergmann
2013-04-03 19:52 ` Jens Axboe

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