summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>2016-05-27 06:10:41 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-05-31 17:52:29 +0800
commit4f8de65bab611a68f40355ac9169edb4d0d33974 (patch)
treefed8110b1923e79c0be812542c53a5cb183e42d8
parent33a36a5bc0a158fa5d37ab15edc90f5928051a7e (diff)
downloadlinux-4f8de65bab611a68f40355ac9169edb4d0d33974.tar.bz2
hwrng: bcm2835 - Read as much data as available
Read the requested number of data from the fifo Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com> Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/char/hw_random/bcm2835-rng.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
index b1e8b7847e9a..75ca820730be 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 = {