From: Vladis Dronov <vdronov@redhat.com>
To: vdronov@redhat.com, Sunil Goutham <sgoutham@marvell.com>,
Bharat Bhushan <bbhushan2@marvell.com>,
Joseph Longever <jlongever@marvell.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] hwrng: cn10k - Optimize cn10k_rng_read()
Date: Wed, 13 Apr 2022 16:16:05 +0200 [thread overview]
Message-ID: <20220413141606.8261-2-vdronov@redhat.com> (raw)
In-Reply-To: <20220413141606.8261-1-vdronov@redhat.com>
This function assumes that sizeof(void) is 1 and arithmetic works for
void pointers. This is a GNU C extention and may not work with other
compilers. Change this by using an u8 pointer.
Also move cn10k_read_trng() out of a loop thus saving some cycles.
Fixes: 38e9791a0209 ("hwrng: cn10k - Add random number generator support")
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
---
drivers/char/hw_random/cn10k-rng.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/char/hw_random/cn10k-rng.c b/drivers/char/hw_random/cn10k-rng.c
index 35001c63648b..dd226630b67d 100644
--- a/drivers/char/hw_random/cn10k-rng.c
+++ b/drivers/char/hw_random/cn10k-rng.c
@@ -90,6 +90,7 @@ static int cn10k_rng_read(struct hwrng *hwrng, void *data,
{
struct cn10k_rng *rng = (struct cn10k_rng *)hwrng->priv;
unsigned int size;
+ u8 *pos = data;
int err = 0;
u64 value;
@@ -102,17 +103,20 @@ static int cn10k_rng_read(struct hwrng *hwrng, void *data,
while (size >= 8) {
cn10k_read_trng(rng, &value);
- *((u64 *)data) = (u64)value;
+ *((u64 *)pos) = value;
size -= 8;
- data += 8;
+ pos += 8;
}
- while (size > 0) {
+ if (size > 0) {
cn10k_read_trng(rng, &value);
- *((u8 *)data) = (u8)value;
- size--;
- data++;
+ while (size > 0) {
+ *pos = (u8)value;
+ value >>= 8;
+ size--;
+ pos++;
+ }
}
return max - size;
--
2.35.1
next prev parent reply other threads:[~2022-04-13 14:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-13 14:16 [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver Vladis Dronov
2022-04-13 14:16 ` Vladis Dronov [this message]
2022-04-13 14:16 ` [PATCH 2/2] hwrng: cn10k - Make check_rng_health() return an error code Vladis Dronov
2022-04-21 10:00 ` [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver Herbert Xu
2022-04-21 10:03 ` Vlad Dronov
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=20220413141606.8261-2-vdronov@redhat.com \
--to=vdronov@redhat.com \
--cc=bbhushan2@marvell.com \
--cc=herbert@gondor.apana.org.au \
--cc=jlongever@marvell.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sgoutham@marvell.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
all inboxes | Powered by JetHome®