* [PATCH 1/3] hwrng: atmel - Add a local variable for struct device pointer
2025-04-10 7:06 [PATCH 0/3] Use a local device pointer for hwrng drivers instead of casting constantly Sakari Ailus
@ 2025-04-10 7:06 ` Sakari Ailus
2025-04-10 7:42 ` Herbert Xu
2025-04-10 7:06 ` [PATCH 2/3] hwrng: mtk " Sakari Ailus
2025-04-10 7:06 ` [PATCH 3/3] hwrng: npcm " Sakari Ailus
2 siblings, 1 reply; 8+ messages in thread
From: Sakari Ailus @ 2025-04-10 7:06 UTC (permalink / raw)
To: linux-crypto
Cc: Olivia Mackall, Herbert Xu, Nicolas Ferre, Sean Wang,
Matthias Brugger, AngeloGioacchino Del Regno, Avi Fishman,
Tomer Maimon, Tali Perry, Uwe Kleine-König, linux-arm-kernel,
linux-mediatek, openbmc
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;
u32 *data = buf;
int ret;
- ret = pm_runtime_get_sync((struct device *)trng->rng.priv);
+ ret = pm_runtime_get_sync(dev);
if (ret < 0) {
- pm_runtime_put_sync((struct device *)trng->rng.priv);
+ pm_runtime_put_sync(dev);
return ret;
}
@@ -79,8 +80,8 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,
ret = 4;
out:
- pm_runtime_mark_last_busy((struct device *)trng->rng.priv);
- pm_runtime_put_sync_autosuspend((struct device *)trng->rng.priv);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_sync_autosuspend(dev);
return ret;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] hwrng: atmel - Add a local variable for struct device pointer
2025-04-10 7:06 ` [PATCH 1/3] hwrng: atmel - Add a local variable for struct device pointer Sakari Ailus
@ 2025-04-10 7:42 ` Herbert Xu
2025-04-10 15:15 ` Sakari Ailus
0 siblings, 1 reply; 8+ messages in thread
From: Herbert Xu @ 2025-04-10 7:42 UTC (permalink / raw)
To: Sakari Ailus
Cc: linux-crypto, Olivia Mackall, Nicolas Ferre, Sean Wang,
Matthias Brugger, AngeloGioacchino Del Regno, Avi Fishman,
Tomer Maimon, Tali Perry, Uwe Kleine-König, linux-arm-kernel,
linux-mediatek, openbmc
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,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] hwrng: atmel - Add a local variable for struct device pointer
2025-04-10 7:42 ` Herbert Xu
@ 2025-04-10 15:15 ` Sakari Ailus
0 siblings, 0 replies; 8+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:15 UTC (permalink / raw)
To: Herbert Xu
Cc: linux-crypto, Olivia Mackall, Nicolas Ferre, Sean Wang,
Matthias Brugger, AngeloGioacchino Del Regno, Avi Fishman,
Tomer Maimon, Tali Perry, Uwe Kleine-König, linux-arm-kernel,
linux-mediatek, openbmc
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.
--
Regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] hwrng: mtk - Add a local variable for struct device pointer
2025-04-10 7:06 [PATCH 0/3] Use a local device pointer for hwrng drivers instead of casting constantly Sakari Ailus
2025-04-10 7:06 ` [PATCH 1/3] hwrng: atmel - Add a local variable for struct device pointer Sakari Ailus
@ 2025-04-10 7:06 ` Sakari Ailus
2025-04-10 7:06 ` [PATCH 3/3] hwrng: npcm " Sakari Ailus
2 siblings, 0 replies; 8+ messages in thread
From: Sakari Ailus @ 2025-04-10 7:06 UTC (permalink / raw)
To: linux-crypto
Cc: Olivia Mackall, Herbert Xu, Nicolas Ferre, Sean Wang,
Matthias Brugger, AngeloGioacchino Del Regno, Avi Fishman,
Tomer Maimon, Tali Perry, Uwe Kleine-König, linux-arm-kernel,
linux-mediatek, openbmc
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/mtk-rng.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c
index 1e3048f2bb38..38e57900080a 100644
--- a/drivers/char/hw_random/mtk-rng.c
+++ b/drivers/char/hw_random/mtk-rng.c
@@ -83,9 +83,10 @@ static bool mtk_rng_wait_ready(struct hwrng *rng, bool wait)
static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
{
struct mtk_rng *priv = to_mtk_rng(rng);
+ struct device *dev = (struct device *)priv->rng.priv;
int retval = 0;
- pm_runtime_get_sync((struct device *)priv->rng.priv);
+ pm_runtime_get_sync(dev);
while (max >= sizeof(u32)) {
if (!mtk_rng_wait_ready(rng, wait))
@@ -97,8 +98,8 @@ static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
max -= sizeof(u32);
}
- pm_runtime_mark_last_busy((struct device *)priv->rng.priv);
- pm_runtime_put_sync_autosuspend((struct device *)priv->rng.priv);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_sync_autosuspend(dev);
return retval || !wait ? retval : -EIO;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/3] hwrng: npcm - Add a local variable for struct device pointer
2025-04-10 7:06 [PATCH 0/3] Use a local device pointer for hwrng drivers instead of casting constantly Sakari Ailus
2025-04-10 7:06 ` [PATCH 1/3] hwrng: atmel - Add a local variable for struct device pointer Sakari Ailus
2025-04-10 7:06 ` [PATCH 2/3] hwrng: mtk " Sakari Ailus
@ 2025-04-10 7:06 ` Sakari Ailus
2025-04-10 9:59 ` kernel test robot
2025-04-10 15:55 ` kernel test robot
2 siblings, 2 replies; 8+ messages in thread
From: Sakari Ailus @ 2025-04-10 7:06 UTC (permalink / raw)
To: linux-crypto
Cc: Olivia Mackall, Herbert Xu, Nicolas Ferre, Sean Wang,
Matthias Brugger, AngeloGioacchino Del Regno, Avi Fishman,
Tomer Maimon, Tali Perry, Uwe Kleine-König, linux-arm-kernel,
linux-mediatek, openbmc
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/npcm-rng.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/char/hw_random/npcm-rng.c b/drivers/char/hw_random/npcm-rng.c
index 9ff00f096f38..beec96391af7 100644
--- a/drivers/char/hw_random/npcm-rng.c
+++ b/drivers/char/hw_random/npcm-rng.c
@@ -54,10 +54,11 @@ static void npcm_rng_cleanup(struct hwrng *rng)
static int npcm_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
{
struct npcm_rng *priv = to_npcm_rng(rng);
+ struct device *dev = (struct device *)priv->rng.priv
int retval = 0;
int ready;
- pm_runtime_get_sync((struct device *)priv->rng.priv);
+ pm_runtime_get_sync(dev);
while (max) {
if (wait) {
@@ -79,8 +80,8 @@ static int npcm_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
max--;
}
- pm_runtime_mark_last_busy((struct device *)priv->rng.priv);
- pm_runtime_put_sync_autosuspend((struct device *)priv->rng.priv);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_sync_autosuspend(dev);
return retval || !wait ? retval : -EIO;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 3/3] hwrng: npcm - Add a local variable for struct device pointer
2025-04-10 7:06 ` [PATCH 3/3] hwrng: npcm " Sakari Ailus
@ 2025-04-10 9:59 ` kernel test robot
2025-04-10 15:55 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2025-04-10 9:59 UTC (permalink / raw)
To: Sakari Ailus, linux-crypto
Cc: oe-kbuild-all, Olivia Mackall, Herbert Xu, Nicolas Ferre,
Sean Wang, Matthias Brugger, AngeloGioacchino Del Regno,
Avi Fishman, Tomer Maimon, Tali Perry, Uwe Kleine-König,
linux-arm-kernel, linux-mediatek, openbmc
Hi Sakari,
kernel test robot noticed the following build errors:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus herbert-cryptodev-2.6/master linus/master v6.15-rc1 next-20250410]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sakari-Ailus/hwrng-atmel-Add-a-local-variable-for-struct-device-pointer/20250410-151223
base: char-misc/char-misc-testing
patch link: https://lore.kernel.org/r/20250410070623.3676647-4-sakari.ailus%40linux.intel.com
patch subject: [PATCH 3/3] hwrng: npcm - Add a local variable for struct device pointer
config: csky-randconfig-001-20250410 (https://download.01.org/0day-ci/archive/20250410/202504101705.PeW9QC3m-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250410/202504101705.PeW9QC3m-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504101705.PeW9QC3m-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
drivers/char/hw_random/npcm-rng.c: In function 'npcm_rng_read':
>> drivers/char/hw_random/npcm-rng.c:58:9: error: expected ',' or ';' before 'int'
58 | int retval = 0;
| ^~~
>> drivers/char/hw_random/npcm-rng.c:78:17: error: 'retval' undeclared (first use in this function)
78 | retval++;
| ^~~~~~
drivers/char/hw_random/npcm-rng.c:78:17: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/char/hw_random/npcm-rng.c:87:1: warning: control reaches end of non-void function [-Wreturn-type]
87 | }
| ^
vim +58 drivers/char/hw_random/npcm-rng.c
c98429297d8b25a Tomer Maimon 2019-09-12 53
c98429297d8b25a Tomer Maimon 2019-09-12 54 static int npcm_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
c98429297d8b25a Tomer Maimon 2019-09-12 55 {
c98429297d8b25a Tomer Maimon 2019-09-12 56 struct npcm_rng *priv = to_npcm_rng(rng);
11fd03b27c8824f Sakari Ailus 2025-04-10 57 struct device *dev = (struct device *)priv->rng.priv
c98429297d8b25a Tomer Maimon 2019-09-12 @58 int retval = 0;
c98429297d8b25a Tomer Maimon 2019-09-12 59 int ready;
c98429297d8b25a Tomer Maimon 2019-09-12 60
11fd03b27c8824f Sakari Ailus 2025-04-10 61 pm_runtime_get_sync(dev);
c98429297d8b25a Tomer Maimon 2019-09-12 62
c2fb644638ae45c Tomer Maimon 2020-09-24 63 while (max) {
c98429297d8b25a Tomer Maimon 2019-09-12 64 if (wait) {
c2fb644638ae45c Tomer Maimon 2020-09-24 65 if (readb_poll_timeout(priv->base + NPCM_RNGCS_REG,
c98429297d8b25a Tomer Maimon 2019-09-12 66 ready,
c98429297d8b25a Tomer Maimon 2019-09-12 67 ready & NPCM_RNG_DATA_VALID,
c98429297d8b25a Tomer Maimon 2019-09-12 68 NPCM_RNG_POLL_USEC,
c98429297d8b25a Tomer Maimon 2019-09-12 69 NPCM_RNG_TIMEOUT_USEC))
c98429297d8b25a Tomer Maimon 2019-09-12 70 break;
c98429297d8b25a Tomer Maimon 2019-09-12 71 } else {
c2fb644638ae45c Tomer Maimon 2020-09-24 72 if ((readb(priv->base + NPCM_RNGCS_REG) &
c98429297d8b25a Tomer Maimon 2019-09-12 73 NPCM_RNG_DATA_VALID) == 0)
c98429297d8b25a Tomer Maimon 2019-09-12 74 break;
c98429297d8b25a Tomer Maimon 2019-09-12 75 }
c98429297d8b25a Tomer Maimon 2019-09-12 76
c2fb644638ae45c Tomer Maimon 2020-09-24 77 *(u8 *)buf = readb(priv->base + NPCM_RNGD_REG);
c2fb644638ae45c Tomer Maimon 2020-09-24 @78 retval++;
c2fb644638ae45c Tomer Maimon 2020-09-24 79 buf++;
c2fb644638ae45c Tomer Maimon 2020-09-24 80 max--;
c98429297d8b25a Tomer Maimon 2019-09-12 81 }
c98429297d8b25a Tomer Maimon 2019-09-12 82
11fd03b27c8824f Sakari Ailus 2025-04-10 83 pm_runtime_mark_last_busy(dev);
11fd03b27c8824f Sakari Ailus 2025-04-10 84 pm_runtime_put_sync_autosuspend(dev);
c98429297d8b25a Tomer Maimon 2019-09-12 85
c98429297d8b25a Tomer Maimon 2019-09-12 86 return retval || !wait ? retval : -EIO;
c98429297d8b25a Tomer Maimon 2019-09-12 @87 }
c98429297d8b25a Tomer Maimon 2019-09-12 88
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 3/3] hwrng: npcm - Add a local variable for struct device pointer
2025-04-10 7:06 ` [PATCH 3/3] hwrng: npcm " Sakari Ailus
2025-04-10 9:59 ` kernel test robot
@ 2025-04-10 15:55 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2025-04-10 15:55 UTC (permalink / raw)
To: Sakari Ailus, linux-crypto
Cc: llvm, oe-kbuild-all, Olivia Mackall, Herbert Xu, Nicolas Ferre,
Sean Wang, Matthias Brugger, AngeloGioacchino Del Regno,
Avi Fishman, Tomer Maimon, Tali Perry, Uwe Kleine-König,
linux-arm-kernel, linux-mediatek, openbmc
Hi Sakari,
kernel test robot noticed the following build errors:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus herbert-cryptodev-2.6/master linus/master v6.15-rc1 next-20250410]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sakari-Ailus/hwrng-atmel-Add-a-local-variable-for-struct-device-pointer/20250410-151223
base: char-misc/char-misc-testing
patch link: https://lore.kernel.org/r/20250410070623.3676647-4-sakari.ailus%40linux.intel.com
patch subject: [PATCH 3/3] hwrng: npcm - Add a local variable for struct device pointer
config: arm-randconfig-001-20250410 (https://download.01.org/0day-ci/archive/20250410/202504102028.H0evWtkl-lkp@intel.com/config)
compiler: clang version 19.1.1 (https://github.com/llvm/llvm-project d401987fe349a87c53fe25829215b080b70c0c1a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250410/202504102028.H0evWtkl-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504102028.H0evWtkl-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/char/hw_random/npcm-rng.c:57:54: error: expected ';' at end of declaration
57 | struct device *dev = (struct device *)priv->rng.priv
| ^
| ;
1 error generated.
vim +57 drivers/char/hw_random/npcm-rng.c
53
54 static int npcm_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
55 {
56 struct npcm_rng *priv = to_npcm_rng(rng);
> 57 struct device *dev = (struct device *)priv->rng.priv
58 int retval = 0;
59 int ready;
60
61 pm_runtime_get_sync(dev);
62
63 while (max) {
64 if (wait) {
65 if (readb_poll_timeout(priv->base + NPCM_RNGCS_REG,
66 ready,
67 ready & NPCM_RNG_DATA_VALID,
68 NPCM_RNG_POLL_USEC,
69 NPCM_RNG_TIMEOUT_USEC))
70 break;
71 } else {
72 if ((readb(priv->base + NPCM_RNGCS_REG) &
73 NPCM_RNG_DATA_VALID) == 0)
74 break;
75 }
76
77 *(u8 *)buf = readb(priv->base + NPCM_RNGD_REG);
78 retval++;
79 buf++;
80 max--;
81 }
82
83 pm_runtime_mark_last_busy(dev);
84 pm_runtime_put_sync_autosuspend(dev);
85
86 return retval || !wait ? retval : -EIO;
87 }
88
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread