mbox series

[0/3] Use a local device pointer for hwrng drivers instead of casting constantly

Message ID 20250410070623.3676647-1-sakari.ailus@linux.intel.com (mailing list archive)
Headers show
Series Use a local device pointer for hwrng drivers instead of casting constantly | expand

Message

Sakari Ailus April 10, 2025, 7:06 a.m. UTC
Hi folks,

Clean up random number reading by adding a local shorthand variable for a
struct device pointer used on multiple Runtime PM functions. The changes
are very similar in all three drivers.

Sakari Ailus (3):
  hwrng: atmel - Add a local variable for struct device pointer
  hwrng: mtk - Add a local variable for struct device pointer
  hwrng: npcm - Add a local variable for struct device pointer

 drivers/char/hw_random/atmel-rng.c | 9 +++++----
 drivers/char/hw_random/mtk-rng.c   | 7 ++++---
 drivers/char/hw_random/npcm-rng.c  | 7 ++++---
 3 files changed, 13 insertions(+), 10 deletions(-)

Comments

Herbert Xu April 10, 2025, 7:42 a.m. UTC | #1
On Thu, Apr 10, 2025 at 10:06:21AM +0300, Sakari Ailus wrote:
> Add a local variable for a struct device pointer instead of obtaining the
> hwrng priv field and casting it as a struct device pointer whenever it's
> needed.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  drivers/char/hw_random/atmel-rng.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c
> index 143406bc6939..5192c39ebaeb 100644
> --- a/drivers/char/hw_random/atmel-rng.c
> +++ b/drivers/char/hw_random/atmel-rng.c
> @@ -56,12 +56,13 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,
>  			   bool wait)
>  {
>  	struct atmel_trng *trng = container_of(rng, struct atmel_trng, rng);
> +	struct device *dev = (struct device *)trng->rng.priv;

Please stop using the priv field and instead add a struct device
pointer to struct atmel_trng.

Thanks,
Sakari Ailus April 10, 2025, 3:15 p.m. UTC | #2
Hi Herbert,

On Thu, Apr 10, 2025 at 03:42:53PM +0800, Herbert Xu wrote:
> On Thu, Apr 10, 2025 at 10:06:21AM +0300, Sakari Ailus wrote:
> > Add a local variable for a struct device pointer instead of obtaining the
> > hwrng priv field and casting it as a struct device pointer whenever it's
> > needed.
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> >  drivers/char/hw_random/atmel-rng.c | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c
> > index 143406bc6939..5192c39ebaeb 100644
> > --- a/drivers/char/hw_random/atmel-rng.c
> > +++ b/drivers/char/hw_random/atmel-rng.c
> > @@ -56,12 +56,13 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,
> >  			   bool wait)
> >  {
> >  	struct atmel_trng *trng = container_of(rng, struct atmel_trng, rng);
> > +	struct device *dev = (struct device *)trng->rng.priv;
> 
> Please stop using the priv field and instead add a struct device
> pointer to struct atmel_trng.

Thanks for the review. I'll do that in v2.