2
0

057-06-v6.15-hwrng-rockchip-store-dev-pointer-in-driver-struct.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. From 8bb8609293ff3d8998d75c8db605c0529e83bcd9 Mon Sep 17 00:00:00 2001
  2. From: Nicolas Frattaroli <[email protected]>
  3. Date: Tue, 4 Feb 2025 16:35:48 +0100
  4. Subject: [PATCH] hwrng: rockchip - store dev pointer in driver struct
  5. The rockchip rng driver does a dance to store the dev pointer in the
  6. hwrng's unsigned long "priv" member. However, since the struct hwrng
  7. member of rk_rng is not a pointer, we can use container_of to get the
  8. struct rk_rng instance from just the struct hwrng*, which means we don't
  9. have to subvert what little there is in C of a type system and can
  10. instead store a pointer to the device struct in the rk_rng itself.
  11. Signed-off-by: Nicolas Frattaroli <[email protected]>
  12. Signed-off-by: Herbert Xu <[email protected]>
  13. ---
  14. drivers/char/hw_random/rockchip-rng.c | 12 ++++++------
  15. 1 file changed, 6 insertions(+), 6 deletions(-)
  16. --- a/drivers/char/hw_random/rockchip-rng.c
  17. +++ b/drivers/char/hw_random/rockchip-rng.c
  18. @@ -54,6 +54,7 @@ struct rk_rng {
  19. void __iomem *base;
  20. int clk_num;
  21. struct clk_bulk_data *clk_bulks;
  22. + struct device *dev;
  23. };
  24. /* The mask in the upper 16 bits determines the bits that are updated */
  25. @@ -70,8 +71,7 @@ static int rk_rng_init(struct hwrng *rng
  26. /* start clocks */
  27. ret = clk_bulk_prepare_enable(rk_rng->clk_num, rk_rng->clk_bulks);
  28. if (ret < 0) {
  29. - dev_err((struct device *) rk_rng->rng.priv,
  30. - "Failed to enable clks %d\n", ret);
  31. + dev_err(rk_rng->dev, "Failed to enable clocks: %d\n", ret);
  32. return ret;
  33. }
  34. @@ -105,7 +105,7 @@ static int rk_rng_read(struct hwrng *rng
  35. u32 reg;
  36. int ret = 0;
  37. - ret = pm_runtime_resume_and_get((struct device *) rk_rng->rng.priv);
  38. + ret = pm_runtime_resume_and_get(rk_rng->dev);
  39. if (ret < 0)
  40. return ret;
  41. @@ -122,8 +122,8 @@ static int rk_rng_read(struct hwrng *rng
  42. /* Read random data stored in the registers */
  43. memcpy_fromio(buf, rk_rng->base + TRNG_RNG_DOUT, to_read);
  44. out:
  45. - pm_runtime_mark_last_busy((struct device *) rk_rng->rng.priv);
  46. - pm_runtime_put_sync_autosuspend((struct device *) rk_rng->rng.priv);
  47. + pm_runtime_mark_last_busy(rk_rng->dev);
  48. + pm_runtime_put_sync_autosuspend(rk_rng->dev);
  49. return (ret < 0) ? ret : to_read;
  50. }
  51. @@ -164,7 +164,7 @@ static int rk_rng_probe(struct platform_
  52. rk_rng->rng.cleanup = rk_rng_cleanup;
  53. }
  54. rk_rng->rng.read = rk_rng_read;
  55. - rk_rng->rng.priv = (unsigned long) dev;
  56. + rk_rng->dev = dev;
  57. rk_rng->rng.quality = 900;
  58. pm_runtime_set_autosuspend_delay(dev, RK_RNG_AUTOSUSPEND_DELAY);