Message ID | 4dafc70f-be7f-bfdc-8845-bd97b27d1c4c@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Herbert Xu |
Headers | show |
Series | hwrng: meson: simplify driver | expand |
Hi Heiner,
On Sat, Feb 18, 2023 at 9:59 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
> + void __iomem *base = (__force void __iomem *)rng->priv;
I find that "(void __force __iomem *)" is the more common order in
other drivers. Which of these is correct is something I cannot tell
though.
Also I would like to hear some other opinions because to me the code
was easier to read before.
Your way is shorter and may save a few bytes (including alignment etc.) though.
Best regards,
Martin
On 19.02.2023 19:26, Martin Blumenstingl wrote: > Hi Heiner, > > On Sat, Feb 18, 2023 at 9:59 PM Heiner Kallweit <hkallweit1@gmail.com> wrote: >> + void __iomem *base = (__force void __iomem *)rng->priv; > I find that "(void __force __iomem *)" is the more common order in > other drivers. Which of these is correct is something I cannot tell > though. > I just looked at this one: #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err) But right, both orders exist. > Also I would like to hear some other opinions because to me the code > was easier to read before. Right, if possible I'd like to avoid it too. However it's the prerequisite for getting rid of struct meson_rng_data. And this simplification outweighs this small drawback IMO. > Your way is shorter and may save a few bytes (including alignment etc.) though. > > > Best regards, > Martin Heiner
On Sat, Feb 18, 2023 at 09:58:07PM +0100, Heiner Kallweit wrote: > Use the priv data member of struct hwrng to make the iomem base address > available in meson_rng_read(). This allows for removing struct > meson_rng_data completely in the next step. > __force is used to silence sparse warnings. > > Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> > --- > drivers/char/hw_random/meson-rng.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c > index a4eb8e35f..bf7a6e594 100644 > --- a/drivers/char/hw_random/meson-rng.c > +++ b/drivers/char/hw_random/meson-rng.c > @@ -17,16 +17,14 @@ > #define RNG_DATA 0x00 > > struct meson_rng_data { > - void __iomem *base; > struct hwrng rng; > }; This is too ugly for words. If you're trying to save memory we should instead get rid of rng.priv and convert the drivers that user it over to this model of embedding struct hwrng inside the driver struct. Thanks,
On 20.02.2023 05:41, Herbert Xu wrote: > On Sat, Feb 18, 2023 at 09:58:07PM +0100, Heiner Kallweit wrote: >> Use the priv data member of struct hwrng to make the iomem base address >> available in meson_rng_read(). This allows for removing struct >> meson_rng_data completely in the next step. >> __force is used to silence sparse warnings. >> >> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> >> --- >> drivers/char/hw_random/meson-rng.c | 14 +++++++------- >> 1 file changed, 7 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c >> index a4eb8e35f..bf7a6e594 100644 >> --- a/drivers/char/hw_random/meson-rng.c >> +++ b/drivers/char/hw_random/meson-rng.c >> @@ -17,16 +17,14 @@ >> #define RNG_DATA 0x00 >> >> struct meson_rng_data { >> - void __iomem *base; >> struct hwrng rng; >> }; > > This is too ugly for words. If you're trying to save memory we > should instead get rid of rng.priv and convert the drivers that > user it over to this model of embedding struct hwrng inside the > driver struct. > OK, then let's omit patches 4 and 5. Patches 1-3 have a Reviewed-by, can you apply them as-is or do you need a resubmit of the series with patch 1-3 only? > Thanks,
On Mon, Feb 20, 2023 at 08:18:18AM +0100, Heiner Kallweit wrote: > > OK, then let's omit patches 4 and 5. > Patches 1-3 have a Reviewed-by, can you apply them as-is or do > you need a resubmit of the series with patch 1-3 only? Sure, no problems. Thanks,
diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c index a4eb8e35f..bf7a6e594 100644 --- a/drivers/char/hw_random/meson-rng.c +++ b/drivers/char/hw_random/meson-rng.c @@ -17,16 +17,14 @@ #define RNG_DATA 0x00 struct meson_rng_data { - void __iomem *base; struct hwrng rng; }; static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { - struct meson_rng_data *data = - container_of(rng, struct meson_rng_data, rng); + void __iomem *base = (__force void __iomem *)rng->priv; - *(u32 *)buf = readl_relaxed(data->base + RNG_DATA); + *(u32 *)buf = readl_relaxed(base + RNG_DATA); return sizeof(u32); } @@ -36,14 +34,15 @@ static int meson_rng_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct meson_rng_data *data; struct clk *core_clk; + void __iomem *base; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; - data->base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(data->base)) - return PTR_ERR(data->base); + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); core_clk = devm_clk_get_optional_enabled(dev, "core"); if (IS_ERR(core_clk)) @@ -52,6 +51,7 @@ static int meson_rng_probe(struct platform_device *pdev) data->rng.name = pdev->name; data->rng.read = meson_rng_read; + data->rng.priv = (__force unsigned long)base; return devm_hwrng_register(dev, &data->rng); }
Use the priv data member of struct hwrng to make the iomem base address available in meson_rng_read(). This allows for removing struct meson_rng_data completely in the next step. __force is used to silence sparse warnings. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/char/hw_random/meson-rng.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)