]> git.baikalelectronics.ru Git - kernel.git/commit
random: silence compiler warnings and fix race
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 14 Jun 2017 22:45:26 +0000 (00:45 +0200)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 20 Jun 2017 01:42:49 +0000 (21:42 -0400)
commitc29e769a54f8e863a44c9c9839bea5400708054e
tree6aacee17db1b1619926d0856d7cf74ef22470fdf
parent93fc5ce3202ade28696ebb47c1e88f336b42f7dd
random: silence compiler warnings and fix race

Odd versions of gcc for the sh4 architecture will actually warn about
flags being used while uninitialized, so we set them to zero. Non crazy
gccs will optimize that out again, so it doesn't make a difference.

Next, over aggressive gccs could inline the expression that defines
use_lock, which could then introduce a race resulting in a lock
imbalance. By using READ_ONCE, we prevent that fate. Finally, we make
that assignment const, so that gcc can still optimize a nice amount.

Finally, we fix a potential deadlock between primary_crng.lock and
batched_entropy_reset_lock, where they could be called in opposite
order. Moving the call to invalidate_batched_entropy to outside the lock
rectifies this issue.

Fixes: 93fc5ce3202ade28696ebb47c1e88f336b42f7dd
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
drivers/char/random.c