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 6C3FAC433FE for ; Wed, 12 Oct 2022 16:23:37 +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=pI4ICfBIDuWffgFQrn6zOdmh7e2iV5efxEFj9cSxMLw=; b=c/FbDgyHnI95ge q93vl/BFmW7178hrVxzX6M7zgIuk5yWfjYFD45DJhHhJgizORt6+7G8ZQ8Jox5CVaiRk8wYkZc5R7 EZmsxl5zR9I6omsV4A7K8r6HFvg47fpFmELr0J7JW/sRJ9WZ0++7N4q/5x1XHBKTytngyDFDOidGV QThWyBuy+6LQCQoc7EEH+1JxHVtH/Rqi7NKg87EAVQh1LUgq4E/NAIImuV4QcUdkwRvdTsK6Knn1C ILOCEe73r+Aqlyu47D2Ei5atYcpFak47zhzs3vU2UNvxa9iWZ29WOcKczBR0KZekR4+f5kbuIfwWB 3CaHNA/kBjt3lZqQzt4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oieVF-008fWI-T4; Wed, 12 Oct 2022 16:22:41 +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-008fMr-94 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=1665591117; bh=3PJXsVojE1yIhCWBte/WZxkCcLEvTSwXh4kCjVhKYUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BM9SRrG5yhctNS3csxOccAcSe9vSkB3S2uNE6KRqTiSY34JigW89/x39nfaRLs6Kf dLdUsEwN9Dh/DTG0XEyco++ecN6flXxf9+UxHPG2iNlYEEMuZOm8BKEH9+HT7moR5f 3+SIWdshFStDyvBTir4GfYUmpMZTWXbXsSYZg3C5Pt+qRoA8q3NAYNJIxcCYhxgjKL 9V+lRum8MNl+/6ZHJdS/qRZvP4g4dQ9nb6ftCi2bTahAJKB1gxCAPjBGtR63Dy6tUq NJ5vJI/+JUHuKiaksFyOdvDS7yF5k7chQ2MrGK7vmdhTC0njx+reJ/Q4zjG5omh2VG c6hwfMij99J+g== 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 4FB2E1ACF; Wed, 12 Oct 2022 18:11:57 +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 2/2] hwrng: stm32 - fix read of the last word Date: Wed, 12 Oct 2022 18:09:24 +0200 Message-Id: <20221012160924.12226-3-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_755879_6B998731 X-CRM114-Status: GOOD ( 12.15 ) 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 samples TRNG by 4 bytes until at least 5 bytes are free in the input buffer. The last four bytes are never read. For example, 60 bytes are returned in case the input buffer size is 64 bytes. Read until at least 4 bytes are free in the input buffer. Fill the buffer entirely in case the buffer size is divisible by 4. Cc: Oleg Karfich Signed-off-by: Tomas Marek --- 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 8eaacefd498b..366edda4848b 100644 --- a/drivers/char/hw_random/stm32-rng.c +++ b/drivers/char/hw_random/stm32-rng.c @@ -44,7 +44,7 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) pm_runtime_get_sync((struct device *) priv->rng.priv); - while (max > sizeof(u32)) { + while (max >= sizeof(u32)) { sr = readl_relaxed(priv->base + RNG_SR); /* Manage timeout which is based on timer and take */ /* care of initial delay time when enabling rng */ -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel