From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F989C4332F for ; Wed, 12 Oct 2022 16:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+VkQEWZ29CUkj2+1Jm4vUQ+KUT/Fb+rwTGkiWimvxuU=; b=pHYT2t7fBtdXB/ LBJx1VfMJd3NsW6lNvTjYcLFU4Jydvp7Vphpdqv3WJaSnIDVtmGm6Aaazck7yEz3Mahs6yz4GvKD6 sL0xnNCGrdzGTq2dOquM+pDPS8v/armszsIjFGEtzuBIuGcoVH8yJKuMvZj89BCGubfVymofJydF/ wESbatA/ZdaGLV3QRCWc3empzMfquXkSf47WiJRnATG21nR8us9BoILJKkS/MpesmAcomR1vEz1UI qTv0FnFxHh7U/BXTZEy8ZJwPrThpGIl3sopnZshkJ0qDj31tzumR3b2EMX8cAUUfswK0otvwwU/wQ 4m+k3/bEkit3jqXdL7mg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oieV7-008fU7-6p; Wed, 12 Oct 2022 16:22:33 +0000 Received: from smtp.cesky-hosting.cz ([2a00:1ed0:2:0:1:5bef:c8ee:1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oieUp-008fMp-7f for linux-arm-kernel@lists.infradead.org; Wed, 12 Oct 2022 16:22:19 +0000 X-Virus-Scanned: Debian amavisd-new at smtp.cesky-hosting.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=elrest.cz; s=rampa2-202208; t=1665591114; bh=Kxemadi69pFkVKEwR5Ct+aURnZswpdi+grRKg9XSUXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bAJz+2sz2IMgY6tsPsXGxVq5bdbCyOqe0lEq1PgQ5u3JnITtPyURer2dO+loY7E5x ES28+H560S8Lw3Yr6erJ9FdbqY8sQckLpc2YuRtsT+J911nqp+ERQ3aFJPGDP/oXg7 4jvGrefQ1rnZSwsi6lJYW4AC8ZIQsdPeVv2huIXYWEEL8SOV6M67z+9dm5QpgePIUZ 6/uzYAvHawwfnfHHQmMEFbrDKJFnem3we8VmIab58vwiJL46zo0WjDDbprT6IdSQ8y jWjub3fTeVjqu6L2U/u49zsdHpy1qBqP9VmtcTcvrt6cbQEiVT/B3ztfQgLX+yyu/M 9D3XpiQJPxiqw== X-Thin-Conversation: conversation Received: from localhost.localdomain (unknown [5.181.92.50]) (Authenticated sender: tomas.marek@elrest.cz) by smtp.cesky-hosting.cz (Postfix) with ESMTPSA id 81D451498; Wed, 12 Oct 2022 18:11:54 +0200 (CEST) From: Tomas Marek To: mpm@selenic.com, herbert@gondor.apana.org.au Cc: mcoquelin.stm32@gmail.com, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, alexandre.torgue@foss.st.com, oleg.karfich@wago.com, Tomas Marek Subject: [PATCH 1/2] hwrng: stm32 - fix number of returned bytes on read Date: Wed, 12 Oct 2022 18:09:23 +0200 Message-Id: <20221012160924.12226-2-tomas.marek@elrest.cz> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221012160924.12226-1-tomas.marek@elrest.cz> References: <20221012160924.12226-1-tomas.marek@elrest.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221012_092215_758373_B26FEE4B X-CRM114-Status: GOOD ( 13.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The stm32_rng_read() function uses `retval` variable as a counter of generated random bytes. However, the same variable is used to store a result of the polling function in case the driver is waiting until the TRNG is ready. The TRNG generates random numbers by 16B. One loop read 4B. So, the function calls the polling every 16B, i.e. every 4th loop. The `retval` counter is reset on poll call and only number of bytes read after the last poll call is returned to the caller. The remaining sampled random bytes (for example 48 out of 64 in case 64 bytes are read) are not used. Use different variable to store the polling function result and do not overwrite `retval` counter. Cc: Oleg Karfich Signed-off-by: Tomas Marek --- drivers/char/hw_random/stm32-rng.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/stm32-rng.c b/drivers/char/hw_random/stm32-rng.c index bc22178f83e8..8eaacefd498b 100644 --- a/drivers/char/hw_random/stm32-rng.c +++ b/drivers/char/hw_random/stm32-rng.c @@ -49,11 +49,13 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) /* Manage timeout which is based on timer and take */ /* care of initial delay time when enabling rng */ if (!sr && wait) { - retval = readl_relaxed_poll_timeout_atomic(priv->base + int ret; + + ret = readl_relaxed_poll_timeout_atomic(priv->base + RNG_SR, sr, sr, 10, 50000); - if (retval) + if (ret) dev_err((struct device *)priv->rng.priv, "%s: timeout %x!\n", __func__, sr); } -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel