Use the mechanism from bitfield.h to read the fifo level field in the
status register. This makes the code a tiny bit simpler.
Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/char/hw_random/imx-rngc.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index a1c24148ed31..861a615ac7df 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -17,6 +17,7 @@
#include <linux/hw_random.h>
#include <linux/completion.h>
#include <linux/io.h>
+#include <linux/bitfield.h>
#define RNGC_VER_ID 0x0000
#define RNGC_COMMAND 0x0004
@@ -44,8 +45,7 @@
#define RNGC_CTRL_AUTO_SEED 0x00000010
#define RNGC_STATUS_ERROR 0x00010000
-#define RNGC_STATUS_FIFO_LEVEL_MASK 0x00000f00
-#define RNGC_STATUS_FIFO_LEVEL_SHIFT 8
+#define RNGC_STATUS_FIFO_LEVEL GENMASK(11, 8)
#define RNGC_STATUS_SEED_DONE 0x00000020
#define RNGC_STATUS_ST_DONE 0x00000010
@@ -133,9 +133,7 @@ static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait)
break;
/* how many random numbers are in FIFO? [0-16] */
- level = (status & RNGC_STATUS_FIFO_LEVEL_MASK) >>
- RNGC_STATUS_FIFO_LEVEL_SHIFT;
-
+ level = FIELD_GET(RNGC_STATUS_FIFO_LEVEL, status);
if (level) {
/* retrieve a random number from FIFO */
*(u32 *)data = readl(rngc->base + RNGC_FIFO);
--
2.30.2
On Thu, Apr 27, 2023 at 08:53:55PM +0200, Martin Kaiser wrote:
>
> @@ -133,9 +133,7 @@ static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait)
> break;
>
> /* how many random numbers are in FIFO? [0-16] */
> - level = (status & RNGC_STATUS_FIFO_LEVEL_MASK) >>
> - RNGC_STATUS_FIFO_LEVEL_SHIFT;
> -
> + level = FIELD_GET(RNGC_STATUS_FIFO_LEVEL, status);
Wouldn't it be simpler to just get rid of the shift?
Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Thus wrote Herbert Xu ([email protected]):
> On Thu, Apr 27, 2023 at 08:53:55PM +0200, Martin Kaiser wrote:
> > @@ -133,9 +133,7 @@ static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait)
> > break;
> > /* how many random numbers are in FIFO? [0-16] */
> > - level = (status & RNGC_STATUS_FIFO_LEVEL_MASK) >>
> > - RNGC_STATUS_FIFO_LEVEL_SHIFT;
> > -
> > + level = FIELD_GET(RNGC_STATUS_FIFO_LEVEL, status);
> Wouldn't it be simpler to just get rid of the shift?
Yes, we're only checking that level > 0, there's no need for the shift.
I'll submit a new version of the patch.
Thanks,
Martin