From d1aae06630230daf747ef5bc291c19ea7f046129 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Thu, 13 Apr 2023 13:55:28 -0700 Subject: clk: starfive: Avoid casting iomem pointers Let's use a wrapper struct for the auxiliary_device made in jh7110_reset_controller_register() so that we can stop casting iomem pointers. The casts trip up tools like sparse, and make for some awkward casts that are largely unnecessary. While we're here, change the allocation from devm and actually free the auxiliary_device memory in the release function. This avoids any use after free problems where the parent device driver is unbound from the device but the auxiliuary_device is still in use accessing devm freed memory. Cc: Tommaso Merciai Cc: Emil Renner Berthing Cc: Hal Feng Cc: Conor Dooley Cc: Xingyu Wu Reviewed-by: Conor Dooley Fixes: edab7204afe5 ("clk: starfive: Add StarFive JH7110 system clock driver") Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20230413205528.4044216-1-sboyd@kernel.org --- drivers/reset/starfive/reset-starfive-jh7110.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'drivers/reset') diff --git a/drivers/reset/starfive/reset-starfive-jh7110.c b/drivers/reset/starfive/reset-starfive-jh7110.c index c1b3a490d951..2d26ae95c8cc 100644 --- a/drivers/reset/starfive/reset-starfive-jh7110.c +++ b/drivers/reset/starfive/reset-starfive-jh7110.c @@ -7,6 +7,8 @@ #include +#include + #include "reset-starfive-jh71x0.h" #include @@ -33,14 +35,15 @@ static int jh7110_reset_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id) { struct jh7110_reset_info *info = (struct jh7110_reset_info *)(id->driver_data); - void __iomem **base = (void __iomem **)dev_get_drvdata(adev->dev.parent); + struct jh71x0_reset_adev *rdev = to_jh71x0_reset_adev(adev); + void __iomem *base = rdev->base; if (!info || !base) return -ENODEV; return reset_starfive_jh71x0_register(&adev->dev, adev->dev.parent->of_node, - *base + info->assert_offset, - *base + info->status_offset, + base + info->assert_offset, + base + info->status_offset, NULL, info->nr_resets, NULL); -- cgit v1.2.3