Use a local device pointer for hwrng drivers instead of casting constantly
Subsystems (6)
v2 cover Use a local device pointer for hwrng drivers instead of casting constantly
Hi folks,
Clean up random number reading by storing struct device pointer to device context struct. The changes are very similar in all three drivers.
since v2:
- Add a struct device pointer field to device context structs, don't use struct hwrgn priv field for the purpose anymore.
Sakari Ailus (3):
hwrng: atmel - Add struct device pointer to device context struct
hwrng: mtk - Add struct device pointer to device context struct
hwrng: npcm - Add struct device pointer to device context struct
drivers/char/hw_random/atmel-rng.c | 11 ++++++----- drivers/char/hw_random/mtk-rng.c | 9 +++++---- drivers/char/hw_random/npcm-rng.c | 9 +++++---- 3 files changed, 16 insertions(+), 13 deletions(-)
Signature · 1 line
2.39.5
PATCH v2 1/3 hwrng: atmel - Add struct device pointer to device context struct
Add a struct device pointer field to the device's context struct. This makes using the unsigned long priv pointer in struct hwrng unnecessary, so remove that one as well.
--- drivers/char/hw_random/atmel-rng.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/char/hw_random/atmel-rng.c +6 -5
@@ -37,6 +37,7 @@ struct atmel_trng {struct clk *clk;void __iomem *base;struct hwrng rng; +struct device *dev;bool has_half_rate; };
@@ -59,9 +60,9 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,u32 *data = buf;int ret; - ret =pm_runtime_get_sync ((struct device *)trng->rng.priv); + ret =pm_runtime_get_sync (trng->dev);if (ret <0 ) { -pm_runtime_put_sync ((struct device *)trng->rng.priv); +pm_runtime_put_sync (trng->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 (trng->dev); +pm_runtime_put_sync_autosuspend (trng->dev);return ret; }
@@ -134,9 +135,9 @@ static int atmel_trng_probe(struct platform_device *pdev)return -ENODEV ; trng->has_half_rate = data->has_half_rate; + trng->dev = &pdev->dev; trng->rng.name = pdev->name; trng->rng.read = atmel_trng_read; - trng->rng.priv = (unsigned long )&pdev->dev;platform_set_drvdata (pdev, trng);#ifndef CONFIG_PM
Signature · 1 line
2.39.5
PATCH v2 2/3 hwrng: mtk - Add struct device pointer to device context struct
In reply to Sakari AilusAdd a struct device pointer field to the device's context struct. This makes using the unsigned long priv pointer in struct hwrng unnecessary, so remove that one as well.
--- drivers/char/hw_random/mtk-rng.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/char/hw_random/mtk-rng.c +5 -4
@@ -36,6 +36,7 @@ struct mtk_rng {void __iomem *base;struct clk *clk;struct hwrng rng; +struct device *dev; };static int mtk_rng_init (struct hwrng *rng)
@@ -85,7 +86,7 @@ static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)struct mtk_rng *priv =to_mtk_rng (rng);int retval =0 ; -pm_runtime_get_sync ((struct device *)priv->rng.priv); +pm_runtime_get_sync (priv->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 (priv->dev); +pm_runtime_put_sync_autosuspend (priv->dev);return retval || !wait ? retval : -EIO ; }
@@ -112,13 +113,13 @@ static int mtk_rng_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + priv->dev = &pdev->dev; priv->rng.name = pdev->name;#ifndef CONFIG_PM priv->rng.init = mtk_rng_init; priv->rng.cleanup = mtk_rng_cleanup;#endif priv->rng.read = mtk_rng_read; - priv->rng.priv = (unsigned long )&pdev->dev; priv->rng.quality =900 ; priv->clk =devm_clk_get (&pdev->dev,"rng" );
Signature · 1 line
2.39.5
PATCH v2 3/3 hwrng: npcm - Add struct device pointer to device context struct
In reply to Sakari AilusAdd a struct device pointer field to the device's context struct. This makes using the unsigned long priv pointer in struct hwrng unnecessary, so remove that one as well.
--- drivers/char/hw_random/npcm-rng.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/char/hw_random/npcm-rng.c +5 -4
@@ -32,6 +32,7 @@struct npcm_rng {void __iomem *base;struct hwrng rng; +struct device *dev;u32 clkp; };
@@ -57,7 +58,7 @@ static int npcm_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)int retval =0 ;int ready; -pm_runtime_get_sync ((struct device *)priv->rng.priv); +pm_runtime_get_sync (priv->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 (priv->dev); +pm_runtime_put_sync_autosuspend (priv->dev);return retval || !wait ? retval : -EIO ; }
@@ -109,7 +110,7 @@ static int npcm_rng_probe(struct platform_device *pdev)#endif priv->rng.name = pdev->name; priv->rng.read = npcm_rng_read; - priv->rng.priv = (unsigned long )&pdev->dev; + priv->dev = &pdev->dev; priv->clkp = (u32 )(uintptr_t )of_device_get_match_data (&pdev->dev);writel (NPCM_RNG_M1ROSEL , priv->base +NPCM_RNGMODE_REG );
Signature · 1 line
2.39.5
Herbert Xu
maintainerQuoted 15 lines · Sakari Ailus
Hi folks,
Clean up random number reading by storing struct device pointer to device context struct. The changes are very similar in all three drivers.
since v2:
- Add a struct device pointer field to device context structs, don't use struct hwrgn priv field for the purpose anymore.
Sakari Ailus (3):
hwrng: atmel - Add struct device pointer to device context struct
hwrng: mtk - Add struct device pointer to device context struct
hwrng: npcm - Add struct device pointer to device context struct
Quoted 7 lines
drivers/char/hw_random/atmel-rng.c | 11 ++++++----- drivers/char/hw_random/mtk-rng.c | 9 +++++---- drivers/char/hw_random/npcm-rng.c | 9 +++++---- 3 files changed, 16 insertions(+), 13 deletions(-)Signature · 1 line
2.39.5
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt