From: Tomas Marek <tomas.marek@elrest.cz>
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 <tomas.marek@elrest.cz>
Subject: [PATCH 2/2] hwrng: stm32 - fix read of the last word
Date: Wed, 12 Oct 2022 18:09:24 +0200 [thread overview]
Message-ID: <20221012160924.12226-3-tomas.marek@elrest.cz> (raw)
In-Reply-To: <20221012160924.12226-1-tomas.marek@elrest.cz>
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 <oleg.karfich@wago.com>
Signed-off-by: Tomas Marek <tomas.marek@elrest.cz>
---
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
next prev parent reply other threads:[~2022-10-12 16:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 16:09 [PATCH 0/2] hwrng: stm32 - improve performance Tomas Marek
2022-10-12 16:09 ` [PATCH 1/2] hwrng: stm32 - fix number of returned bytes on read Tomas Marek
2022-10-21 10:41 ` Herbert Xu
2022-10-25 14:41 ` Tomas Marek
2022-10-12 16:09 ` Tomas Marek [this message]
2022-10-21 11:39 ` [PATCH 0/2] hwrng: stm32 - improve performance Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221012160924.12226-3-tomas.marek@elrest.cz \
--to=tomas.marek@elrest.cz \
--cc=alexandre.torgue@foss.st.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=mpm@selenic.com \
--cc=oleg.karfich@wago.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox