diff mbox series

[1/3] hwrng: imx-rngc - use bitfield macros to read fifo level

Message ID 20230427185357.923412-2-martin@kaiser.cx (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series hwrng: imx-rngc - simplify register definitions | expand

Commit Message

Martin Kaiser April 27, 2023, 6:53 p.m. UTC
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 <martin@kaiser.cx>
---
 drivers/char/hw_random/imx-rngc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Herbert Xu May 11, 2023, 5:16 a.m. UTC | #1
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,
Martin Kaiser May 11, 2023, 7:43 a.m. UTC | #2
Thus wrote Herbert Xu (herbert@gondor.apana.org.au):

> 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
diff mbox series

Patch

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);