From patchwork Tue May 24 08:32:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9132989 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 32D82607D3 for ; Tue, 24 May 2016 08:33:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A61328233 for ; Tue, 24 May 2016 08:33:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F07F28288; Tue, 24 May 2016 08:33:41 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 C304B28233 for ; Tue, 24 May 2016 08:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754626AbcEXIdS (ORCPT ); Tue, 24 May 2016 04:33:18 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:58162 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754614AbcEXIdP (ORCPT ); Tue, 24 May 2016 04:33:15 -0400 Received: from wuerfel.localnet ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue003) with ESMTPSA (Nemesis) id 0Mefpk-1auBYe06Lg-00OHKo; Tue, 24 May 2016 10:32:40 +0200 From: Arnd Bergmann To: Maxime Coquelin Cc: "linux-arm-kernel@lists.infradead.org" , Sudip Mukherjee , Matt Mackall , Herbert Xu , "linux-kernel@vger.kernel.org" , linux-crypto@vger.kernel.org Subject: Re: [PATCH] hwrng: stm32 - fix build warning Date: Tue, 24 May 2016 10:32:34 +0200 Message-ID: <12548318.auB4PSA3KC@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-22-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <1464007448-25395-1-git-send-email-sudipm.mukherjee@gmail.com> <6297051.TAxtzW5OIB@wuerfel> MIME-Version: 1.0 X-Provags-ID: V03:K0:JCtPIhnETcuBStwKarRrgy3SgRMr5xQ+Y0YO+yyDaVsIWjqm3H8 oTBmLmPmySptHa7vGGHRJAQajEWdRHW+pQcS4sXnpKHfcURncDgWEwIEwRtVet7YD34mJRm uLxQIoqF8T+7MNBoxddfuH2ymR3Pvjv7Cj+34SFT/n3Az2PpfoUeIwO3Cw7fmWcCCJzGQlM 1vHM4ajgCSdg3GxrLbOCw== X-UI-Out-Filterresults: notjunk:1; V01:K0:S9bDHzuMYV0=:L3wuptE/SCznpKNJMo4h1C iNXyAMiU1dlFzwpmZqd8IVSls4GXIy1uFf7aQQp3c2pPTrYkQXIkGo9OFRPW48sScz/2C0rAh pXiOdPRmKFJB/OgA08uik9dlb0Pmpj1EB+j54COInMoUqEhIqWjt+8lWlHWCdCY8eJG0hZecj kpsf0F0i/ar0IyF9IJU2aAxb/0m/G5SLjP2Y8sPvPz5f0nTH9+zLy8cAoIMxSVoqrgS0iQJL4 b1qu3YLzIaFqsvm7YdGsapT/NHtZeyiYR2/UJFiIRKUccpPMYveBv8BgCzrz/hfyqojvJmS7s B/+E67Si0LR4n4WFIdnzab1ondfuKsG5lPEkddfwZuQj/bLu5IfHQWxqQ0fyCn9U6zRc4ApRb RtKw5tROqhPnTIvSsF/95kDWEexZHKhI7Yhd9BDjzdUFR+0DFQDz+eCNd5PCTemgpAaAORPge 55fJ9aDMgy7hIo+c0jeW8zJxNZb3oZXU9T9g8RXfvk/rD/CpJdD25PUSBmfHKxNnA0w3MBVjS Mf82w8+jxDhhnTFkrAzRouE7vGrg27rzdO6eCvGBP0lAXPvI5nY0DXQfZ6pm2Z3G+fc/+82eO wZJ+g2q0ZT4UuvSa6eXCswP/6Lz+UMTOigoE9G/VjzSZKEsC2sQTFB48S1qdZLA0mFMynQe65 cWO5LCpMRHVdY+Z/gkLSoEv+Bb2UvOvwKPnmxYh24xfgoCk0YMCFlWneteYFy0NyAcRsMdhpk UTJRNjEaZklGWn4n 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 On Tuesday, May 24, 2016 9:59:41 AM CEST Maxime Coquelin wrote: > 2016-05-23 22:35 GMT+02:00 Arnd Bergmann : > > On Monday, May 23, 2016 6:14:08 PM CEST Sudip Mukherjee wrote: > >> 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. Ah, you are right. > Maybe the better way is just to initialize sr with status register content? > 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; I think that introduces a bug: you really want to read the status register on each loop iteration. How about moving the error handling into the loop itself? Arnd --- 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..fceacd809462 100644 --- a/drivers/char/hw_random/stm32-rng.c +++ b/drivers/char/hw_random/stm32-rng.c @@ -59,6 +59,10 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) while (max > sizeof(u32)) { sr = readl_relaxed(priv->base + RNG_SR); + if (WARN_ONCE(sr & (RNG_SR_SEIS | RNG_SR_CEIS), + "bad RNG status - %x\n", sr)) + writel_relaxed(0, priv->base + RNG_SR); + if (!sr && wait) { unsigned int timeout = RNG_TIMEOUT; @@ -79,10 +83,6 @@ 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), - "bad RNG status - %x\n", sr)) - writel_relaxed(0, priv->base + RNG_SR); - pm_runtime_mark_last_busy((struct device *) priv->rng.priv); pm_runtime_put_sync_autosuspend((struct device *) priv->rng.priv);