Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1405500 > unrolled thread
| Started by | Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com> |
|---|---|
| First post | 2016-05-23 18:30 +0200 |
| Last post | 2016-05-24 04:30 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 4/4] hwrng: bcm2835: Read as much data as available Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com> - 2016-05-23 18:30 +0200
Re: [PATCH 4/4] hwrng: bcm2835: Read as much data as available Eric Anholt <eric@anholt.net> - 2016-05-24 04:30 +0200
| From | Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com> |
|---|---|
| Date | 2016-05-23 18:30 +0200 |
| Subject | [PATCH 4/4] hwrng: bcm2835: Read as much data as available |
| Message-ID | <rC0TU-8cl-21@gated-at.bofh.it> |
Read the requested number of data from the fifo
Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
---
drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
index b1e8b78..9bbdc07 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -43,6 +43,8 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
bool wait)
{
void __iomem *rng_base = (void __iomem *)rng->priv;
+ u32 max_words = max/sizeof(u32);
+ u32 num_words, count;
while ((__raw_readl(rng_base + RNG_STATUS) >> 24) == 0) {
if (!wait)
@@ -50,8 +52,14 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
cpu_relax();
}
- *(u32 *)buf = __raw_readl(rng_base + RNG_DATA);
- return sizeof(u32);
+ num_words = (readl(rng_base + RNG_STATUS) >> 24);
+ if (num_words > max_words)
+ num_words = max_words;
+
+ for (count = 0; count < num_words; count++)
+ ((u32 *)buf)[count] = readl(rng_base + RNG_DATA);
+
+ return (num_words * sizeof(u32));
}
static struct hwrng bcm2835_rng_ops = {
--
2.1.0
[toc] | [next] | [standalone]
| From | Eric Anholt <eric@anholt.net> |
|---|---|
| Date | 2016-05-24 04:30 +0200 |
| Message-ID | <rCagy-5zr-19@gated-at.bofh.it> |
| In reply to | #1405500 |
[Multipart message — attachments visible in raw view] — view raw
Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
writes:
> Read the requested number of data from the fifo
>
> Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
> ---
> drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
> index b1e8b78..9bbdc07 100644
> --- a/drivers/char/hw_random/bcm2835-rng.c
> +++ b/drivers/char/hw_random/bcm2835-rng.c
> @@ -43,6 +43,8 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
> bool wait)
> {
> void __iomem *rng_base = (void __iomem *)rng->priv;
> + u32 max_words = max/sizeof(u32);
Style fix: Binary operators get a space on each side, so
"max / sizeof(u32);"
> @@ -50,8 +52,14 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
> cpu_relax();
> }
>
> - *(u32 *)buf = __raw_readl(rng_base + RNG_DATA);
> - return sizeof(u32);
> + num_words = (readl(rng_base + RNG_STATUS) >> 24);
Optional cleanup: here and in the return statement, drop the extra
parenthesis.
Functionality-wise, this patch looks great to me, and should make the
driver more efficient. With at least the binary operators change done,
it will be:
Reviewed-by: Eric Anholt <eric@anholt.net>
Thanks!
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web