Re: [PATCH] drivers/char/random.c: fix uninitialized value warning
From: Arnd Bergmann
Date: Wed Jul 18 2018 - 11:38:54 EST
On Wed, Jul 18, 2018 at 9:11 AM, Constantine Shulyupin
<const@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxx>
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