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 1/2] hwrng: stm32 - fix number of returned bytes on read
Date: Wed, 12 Oct 2022 18:09:23 +0200 [thread overview]
Message-ID: <20221012160924.12226-2-tomas.marek@elrest.cz> (raw)
In-Reply-To: <20221012160924.12226-1-tomas.marek@elrest.cz>
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 <oleg.karfich@wago.com>
Signed-off-by: Tomas Marek <tomas.marek@elrest.cz>
---
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
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 ` Tomas Marek [this message]
2022-10-21 10:41 ` [PATCH 1/2] hwrng: stm32 - fix number of returned bytes on read Herbert Xu
2022-10-25 14:41 ` Tomas Marek
2022-10-12 16:09 ` [PATCH 2/2] hwrng: stm32 - fix read of the last word Tomas Marek
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-2-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