From patchwork Tue May 24 07:59:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 9132943 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 084586075E for ; Tue, 24 May 2016 07:59:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1B6028287 for ; Tue, 24 May 2016 07:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E65F42829E; Tue, 24 May 2016 07:59:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 502CA2829F for ; Tue, 24 May 2016 07:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754495AbcEXH7n (ORCPT ); Tue, 24 May 2016 03:59:43 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:33891 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753542AbcEXH7n (ORCPT ); Tue, 24 May 2016 03:59:43 -0400 Received: by mail-qk0-f194.google.com with SMTP id i7so1102751qkd.1; Tue, 24 May 2016 00:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=fgcqNjtwgraHhi0JaAfiT6uVwuOXbnKBFVWwbVx4QUg=; b=zYnwa4r5Jm7f8afX4NHuJLiiLWohKuGNBtTVtm3qK0V4OZ17l5q+p5wAPMhyzbOxhl e0WiepIhU0VthCT0+JioCRT4huTTxrLVOQtX5pVpRlkgnWQ5a5KbBNfj5O4vmKN5jfBT NgJh/pAND2Fq2TeKfRAQQnmieYQzGkUls3xh0ZhOgJbcZ/Gaxaf9HUD+DqwSGYX6qwBR odczFmD3yirlOJlpwSTKOnTs7eo97z4Sn6f3rpOW+z4e/fJRmhBYWkgqdvrEVS/PtuBp LBF5tWHxW3nAKHw4GAQBCMJ9Ml2x/V42rTNKvL2zoNss4b/aTbXyzE+t0tSJpqA8RFda hY6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=fgcqNjtwgraHhi0JaAfiT6uVwuOXbnKBFVWwbVx4QUg=; b=E/MRch1uXm6RIGz4MOZYHiI+PCgu98VakzAadpv6cIAnSsFo38hOi9edZL3sl3Jg5R 4jbIQLlJyS/ls1qK78AVPZdfVGLMYpI8Mf5KxhsBL/hrE5f/cVIcPQh5ovMnJ2h+mUGY //kgPq5q5C7WybCtPWM55uhyaYwdQTEMT8HdxEbuno79k1odBT6sL+qjfwbpxxVW3eDM 1OB6gzNyLjWyTqJyfxePiX7k+MuWF4/sP6EzGSW0n1WvzaHocszPcT9c3zL/e+YMKtNX ypcVpr+b7RQF/gjl8mJg46Fr8UDLcj/GQujPdhdIuv2vdAHA0Jv0QAx+5Ws/2DXmCyTi rZwQ== X-Gm-Message-State: ALyK8tLr3T8OdU8IacLhf4Rtl+jZYnKbGBJeenHN122uLNKkM4YsOaIPRzanYDQSYttv9lfT+1oHVECD7QnQHw== MIME-Version: 1.0 X-Received: by 10.55.127.129 with SMTP id a123mr2112892qkd.22.1464076781847; Tue, 24 May 2016 00:59:41 -0700 (PDT) Received: by 10.55.8.142 with HTTP; Tue, 24 May 2016 00:59:41 -0700 (PDT) In-Reply-To: <6297051.TAxtzW5OIB@wuerfel> References: <1464007448-25395-1-git-send-email-sudipm.mukherjee@gmail.com> <6297051.TAxtzW5OIB@wuerfel> Date: Tue, 24 May 2016 09:59:41 +0200 Message-ID: Subject: Re: [PATCH] hwrng: stm32 - fix build warning From: Maxime Coquelin To: Arnd Bergmann Cc: "linux-arm-kernel@lists.infradead.org" , Sudip Mukherjee , Matt Mackall , Herbert Xu , "linux-kernel@vger.kernel.org" , linux-crypto@vger.kernel.org Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 2016-05-23 22:35 GMT+02:00 Arnd Bergmann : > On Monday, May 23, 2016 6:14:08 PM CEST Sudip Mukherjee wrote: >> We have been getting build warning about: >> drivers/char/hw_random/stm32-rng.c: In function 'stm32_rng_read': >> drivers/char/hw_random/stm32-rng.c:82:19: warning: 'sr' may be used >> uninitialized in this function >> >> On checking the code it turns out that sr can never be used >> uninitialized as sr is getting initialized in the while loop and while >> loop will always execute as the minimum value of max can be 32. >> So just initialize sr to 0 while declaring it to silence the compiler. >> >> Signed-off-by: Sudip Mukherjee >> --- > > I notice that you are using a really old compiler. While this warning > seems to be valid in the sense that the compiler should figure out that > the variable might be used uninitialized, please update your toolchain > before reporting other such problems, as gcc-4.6 had a lot more false > positives that newer ones (5.x or 6.x) have. > >> >> build log at: >> https://travis-ci.org/sudipm-mukherjee/parport/jobs/132180906 >> >> drivers/char/hw_random/stm32-rng.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/char/hw_random/stm32-rng.c b/drivers/char/hw_random/stm32-rng.c >> index 92a8106..0533370 100644 >> --- a/drivers/char/hw_random/stm32-rng.c >> +++ b/drivers/char/hw_random/stm32-rng.c >> @@ -52,7 +52,7 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) >> { >> struct stm32_rng_private *priv = >> container_of(rng, struct stm32_rng_private, rng); >> - u32 sr; >> + u32 sr = 0; >> int retval = 0; >> >> pm_runtime_get_sync((struct device *) priv->rng.priv); > > Does this work as well? > > diff --git a/drivers/char/hw_random/stm32-rng.c b/drivers/char/hw_random/stm32-rng.c > index 92a810648bd0..5c836b0afa40 100644 > --- a/drivers/char/hw_random/stm32-rng.c > +++ b/drivers/char/hw_random/stm32-rng.c > @@ -79,7 +79,7 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) > max -= sizeof(u32); > } > > - if (WARN_ONCE(sr & (RNG_SR_SEIS | RNG_SR_CEIS), > + if (WARN_ONCE(retval > 0 && (sr & (RNG_SR_SEIS | RNG_SR_CEIS)), > "bad RNG status - %x\n", sr)) > writel_relaxed(0, priv->base + RNG_SR); > > I think it would be nicer to not add a bogus initialization. Hmm, no sure this nicer. The while loop can break before retval is incremented when sr value is not expected (sr != RNG_SR_DRDY). In that case, we certainly want to print sr value. Maybe the better way is just to initialize sr with status register content? @@ -77,6 +77,8 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) retval += sizeof(u32); data += sizeof(u32); max -= sizeof(u32); + + sr = readl_relaxed(priv->base + RNG_SR); } if (WARN_ONCE(sr & (RNG_SR_SEIS | RNG_SR_CEIS), Regards, Maxime --- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/char/hw_random/stm32-rng.c b/drivers/char/hw_random/stm32-rng.c index 92a810648bd0..07a6659d0fe6 100644 --- a/drivers/char/hw_random/stm32-rng.c +++ b/drivers/char/hw_random/stm32-rng.c @@ -57,8 +57,8 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) pm_runtime_get_sync((struct device *) priv->rng.priv); + sr = readl_relaxed(priv->base + RNG_SR); while (max > sizeof(u32)) { - sr = readl_relaxed(priv->base + RNG_SR); if (!sr && wait) { unsigned int timeout = RNG_TIMEOUT;