Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751883AbdFGSQL (ORCPT ); Wed, 7 Jun 2017 14:16:11 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:53441 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751717AbdFGSQJ (ORCPT ); Wed, 7 Jun 2017 14:16:09 -0400 MIME-Version: 1.0 In-Reply-To: <201706080107.xhkKszte%fengguang.wu@intel.com> References: <20170606005108.5646-4-Jason@zx2c4.com> <201706080107.xhkKszte%fengguang.wu@intel.com> From: "Jason A. Donenfeld" Date: Wed, 7 Jun 2017 20:16:05 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 03/13] random: invalidate batched entropy after crng init To: kbuild test robot Cc: kbuild-all@01.org, "Theodore Ts'o" , Linux Crypto Mailing List , LKML , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman , David Miller Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1169 Lines: 36 Strange, not all compilers do this warning. Fixing with: diff --git a/drivers/char/random.c b/drivers/char/random.c index 12758db..5252690 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -2061,8 +2061,8 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u64); u64 get_random_u64(void) { u64 ret; - bool use_lock = crng_init < 2; - unsigned long flags; + const bool use_lock = READ_ONCE(crng_init) < 2; + unsigned long flags = 0; struct batched_entropy *batch; #if BITS_PER_LONG == 64 @@ -2099,8 +2099,8 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u32); u32 get_random_u32(void) { u32 ret; - bool use_lock = crng_init < 2; - unsigned long flags; + const bool use_lock = READ_ONCE(crng_init) < 2; + unsigned long flags = 0; struct batched_entropy *batch; if (arch_get_random_int(&ret)) Const, because it's more correct. READ_ONCE to be certain that the compiler doesn't try to paste the expression into both uses. And finally flags=0 to shutup the compiler. If anybody has a better way of approaching this, feel free to chime in.