1 From 8bb8609293ff3d8998d75c8db605c0529e83bcd9 Mon Sep 17 00:00:00 2001
2 From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
3 Date: Tue, 4 Feb 2025 16:35:48 +0100
4 Subject: [PATCH] hwrng: rockchip - store dev pointer in driver struct
6 The rockchip rng driver does a dance to store the dev pointer in the
7 hwrng's unsigned long "priv" member. However, since the struct hwrng
8 member of rk_rng is not a pointer, we can use container_of to get the
9 struct rk_rng instance from just the struct hwrng*, which means we don't
10 have to subvert what little there is in C of a type system and can
11 instead store a pointer to the device struct in the rk_rng itself.
13 Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
14 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
16 drivers/char/hw_random/rockchip-rng.c | 12 ++++++------
17 1 file changed, 6 insertions(+), 6 deletions(-)
19 --- a/drivers/char/hw_random/rockchip-rng.c
20 +++ b/drivers/char/hw_random/rockchip-rng.c
21 @@ -54,6 +54,7 @@ struct rk_rng {
24 struct clk_bulk_data *clk_bulks;
28 /* The mask in the upper 16 bits determines the bits that are updated */
29 @@ -70,8 +71,7 @@ static int rk_rng_init(struct hwrng *rng
31 ret = clk_bulk_prepare_enable(rk_rng->clk_num, rk_rng->clk_bulks);
33 - dev_err((struct device *) rk_rng->rng.priv,
34 - "Failed to enable clks %d\n", ret);
35 + dev_err(rk_rng->dev, "Failed to enable clocks: %d\n", ret);
39 @@ -105,7 +105,7 @@ static int rk_rng_read(struct hwrng *rng
43 - ret = pm_runtime_resume_and_get((struct device *) rk_rng->rng.priv);
44 + ret = pm_runtime_resume_and_get(rk_rng->dev);
48 @@ -122,8 +122,8 @@ static int rk_rng_read(struct hwrng *rng
49 /* Read random data stored in the registers */
50 memcpy_fromio(buf, rk_rng->base + TRNG_RNG_DOUT, to_read);
52 - pm_runtime_mark_last_busy((struct device *) rk_rng->rng.priv);
53 - pm_runtime_put_sync_autosuspend((struct device *) rk_rng->rng.priv);
54 + pm_runtime_mark_last_busy(rk_rng->dev);
55 + pm_runtime_put_sync_autosuspend(rk_rng->dev);
57 return (ret < 0) ? ret : to_read;
59 @@ -164,7 +164,7 @@ static int rk_rng_probe(struct platform_
60 rk_rng->rng.cleanup = rk_rng_cleanup;
62 rk_rng->rng.read = rk_rng_read;
63 - rk_rng->rng.priv = (unsigned long) dev;
65 rk_rng->rng.quality = 900;
67 pm_runtime_set_autosuspend_delay(dev, RK_RNG_AUTOSUSPEND_DELAY);