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: 9132951 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 AFD6D6075E for ; Tue, 24 May 2016 08:01:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A50EE28287 for ; Tue, 24 May 2016 08:01:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99FB52828D; Tue, 24 May 2016 08:01:57 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 95A982828B for ; Tue, 24 May 2016 08:01:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b57G6-0005iR-Rg; Tue, 24 May 2016 08:00:10 +0000 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b57G1-0004Xq-MA for linux-arm-kernel@lists.infradead.org; Tue, 24 May 2016 08:00:09 +0000 Received: by mail-qk0-x244.google.com with SMTP id l68so1087309qkf.3 for ; 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=i+WhE1v8I6n9lDtMjGguBuZ7IHHVSlq+o3VWYiD+lmibGlA9XtD6A3Z26BiCTnRMOY VpmP4tUsCP3O5/oCZQQhShBHvWQELQIDj9eNM2j8oFOnw/ECkiB27hKT0UpMlxyAG6Og v1M7U6uyik5cJmo07a+rD/OyuHR+EpJkgrLikD4G7XoNvkqPPz+6QsyC710Ryej5vEBu 282BjNF/2LKZ2t9SZv0yQJfcqrOXgA7LY2NXGer7eWUh5+IPv76QObnOUnnGIe8WexFa yGBM7RpTMVuQ809OyIr9aazQJAEWMCHljvwwkaObs/FDLHLjZ8ezPbjjKOWPgvXxjrFL 39uA== X-Gm-Message-State: ALyK8tLGhc7WHu4W+P4vu0oJvnQ5dFHYTewNqstOI3VxEjXk1Fqau59f9ZrqpCjGIKM+ZS/CiiFk309PcjuTow== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160524_010005_817806_A311F41F X-CRM114-Status: GOOD ( 21.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Herbert Xu , "linux-kernel@vger.kernel.org" , linux-crypto@vger.kernel.org, Matt Mackall , Sudip Mukherjee , "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 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;