* [PATCH] drivers/char/random.c: fix uninitialized value warning
@ 2018-07-18 7:11 Constantine Shulyupin
2018-07-18 15:24 ` Theodore Y. Ts'o
2018-07-18 15:38 ` Arnd Bergmann
0 siblings, 2 replies; 3+ messages in thread
From: Constantine Shulyupin @ 2018-07-18 7:11 UTC (permalink / raw)
To: Theodore Ts'o, Arnd Bergmann, Greg Kroah-Hartman, open list
Cc: Constantine Shulyupin
Local variable t should be initialized by arch_get_random_int.
Actually on failure of arch_get_random_int, value is not used.
So, just keep the build clean with less warnings.
warning:
drivers/char/random.c: In function ‘write_pool.constprop’:
drivers/char/random.c:1912:11: warning: ‘t’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Signed-off-by: Constantine Shulyupin <const@MakeLinux.com>
---
drivers/char/random.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 283fe390e878..8e51846d0673 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1896,7 +1896,7 @@ static int
write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
{
size_t bytes;
- __u32 t, buf[16];
+ __u32 t = 0, buf[16];
const char __user *p = buffer;
while (count > 0) {
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] drivers/char/random.c: fix uninitialized value warning
2018-07-18 7:11 [PATCH] drivers/char/random.c: fix uninitialized value warning Constantine Shulyupin
@ 2018-07-18 15:24 ` Theodore Y. Ts'o
2018-07-18 15:38 ` Arnd Bergmann
1 sibling, 0 replies; 3+ messages in thread
From: Theodore Y. Ts'o @ 2018-07-18 15:24 UTC (permalink / raw)
To: Constantine Shulyupin; +Cc: Arnd Bergmann, Greg Kroah-Hartman, open list
On Wed, Jul 18, 2018 at 10:11:52AM +0300, Constantine Shulyupin wrote:
> Local variable t should be initialized by arch_get_random_int.
> Actually on failure of arch_get_random_int, value is not used.
> So, just keep the build clean with less warnings.
>
> warning:
> drivers/char/random.c: In function ‘write_pool.constprop’:
> drivers/char/random.c:1912:11: warning: ‘t’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>
> Signed-off-by: Constantine Shulyupin <const@MakeLinux.com>
There was a more significant problem which Arnd pointed out, which is
I had reversed the sense of the test in arch_get_random_int(). I've
since fixed this, and the current random tree is clean of warnings.
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers/char/random.c: fix uninitialized value warning
2018-07-18 7:11 [PATCH] drivers/char/random.c: fix uninitialized value warning Constantine Shulyupin
2018-07-18 15:24 ` Theodore Y. Ts'o
@ 2018-07-18 15:38 ` Arnd Bergmann
1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2018-07-18 15:38 UTC (permalink / raw)
To: Constantine Shulyupin; +Cc: Theodore Ts'o, Greg Kroah-Hartman, open list
On Wed, Jul 18, 2018 at 9:11 AM, Constantine Shulyupin
<const@makelinux.com> wrote:
> Local variable t should be initialized by arch_get_random_int.
> Actually on failure of arch_get_random_int, value is not used.
> So, just keep the build clean with less warnings.
>
> warning:
> drivers/char/random.c: In function ‘write_pool.constprop’:
> drivers/char/random.c:1912:11: warning: ‘t’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>
> Signed-off-by: Constantine Shulyupin <const@MakeLinux.com>
You need to be much more careful with fixes like this one. As Ted explained,
the warning was about a real bug here, and adding an incorrect initialization
just made it harder to find that bug.
There are many cases in which the compiler does have a false-positive or
a false-negative -Wmaybe-uninitialized warning, but in general you should
assume that the compiler is correct. If you add a fake initialization because
you think the compiler is wrong, it's best to link to the gcc bugzilla
describing
that gcc bug, or open a new bug report if it still happens in the
latest compiler
version and hasn't been reported before.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-07-18 15:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-18 7:11 [PATCH] drivers/char/random.c: fix uninitialized value warning Constantine Shulyupin
2018-07-18 15:24 ` Theodore Y. Ts'o
2018-07-18 15:38 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).