diff mbox series

iio: ad4130: Make sure clock provider gets removed

Message ID 20230414150702.518441-1-lars@metafoo.de (mailing list archive)
State Accepted
Headers show
Series iio: ad4130: Make sure clock provider gets removed | expand

Commit Message

Lars-Peter Clausen April 14, 2023, 3:07 p.m. UTC
The ad4130 driver registers a clock provider, but never removes it. This
leaves a stale clock provider behind that references freed clocks when the
device is unbound.

Register a managed action to remove the clock provider when the device is
removed.

Fixes: 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/adc/ad4130.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Jonathan Cameron April 23, 2023, 10:37 a.m. UTC | #1
On Fri, 14 Apr 2023 08:07:02 -0700
Lars-Peter Clausen <lars@metafoo.de> wrote:

> The ad4130 driver registers a clock provider, but never removes it. This
> leaves a stale clock provider behind that references freed clocks when the
> device is unbound.
> 
> Register a managed action to remove the clock provider when the device is
> removed.
> 
> Fixes: 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/ad4130.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c
> index 38394341fd6e..5a5dd5e87ffc 100644
> --- a/drivers/iio/adc/ad4130.c
> +++ b/drivers/iio/adc/ad4130.c
> @@ -1817,6 +1817,11 @@ static const struct clk_ops ad4130_int_clk_ops = {
>  	.unprepare = ad4130_int_clk_unprepare,
>  };
>  
> +static void ad4130_clk_del_provider(void *of_node)
> +{
> +	of_clk_del_provider(of_node);
> +}
> +
>  static int ad4130_setup_int_clk(struct ad4130_state *st)
>  {
>  	struct device *dev = &st->spi->dev;
> @@ -1824,6 +1829,7 @@ static int ad4130_setup_int_clk(struct ad4130_state *st)
>  	struct clk_init_data init;
>  	const char *clk_name;
>  	struct clk *clk;
> +	int ret;
>  
>  	if (st->int_pin_sel == AD4130_INT_PIN_CLK ||
>  	    st->mclk_sel != AD4130_MCLK_76_8KHZ)
> @@ -1843,7 +1849,11 @@ static int ad4130_setup_int_clk(struct ad4130_state *st)
>  	if (IS_ERR(clk))
>  		return PTR_ERR(clk);
>  
> -	return of_clk_add_provider(of_node, of_clk_src_simple_get, clk);
> +	ret = of_clk_add_provider(of_node, of_clk_src_simple_get, clk);
> +	if (ret)
> +		return ret;
> +
> +	return devm_add_action_or_reset(dev, ad4130_clk_del_provider, of_node);
>  }
>  
>  static int ad4130_setup(struct iio_dev *indio_dev)
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c
index 38394341fd6e..5a5dd5e87ffc 100644
--- a/drivers/iio/adc/ad4130.c
+++ b/drivers/iio/adc/ad4130.c
@@ -1817,6 +1817,11 @@  static const struct clk_ops ad4130_int_clk_ops = {
 	.unprepare = ad4130_int_clk_unprepare,
 };
 
+static void ad4130_clk_del_provider(void *of_node)
+{
+	of_clk_del_provider(of_node);
+}
+
 static int ad4130_setup_int_clk(struct ad4130_state *st)
 {
 	struct device *dev = &st->spi->dev;
@@ -1824,6 +1829,7 @@  static int ad4130_setup_int_clk(struct ad4130_state *st)
 	struct clk_init_data init;
 	const char *clk_name;
 	struct clk *clk;
+	int ret;
 
 	if (st->int_pin_sel == AD4130_INT_PIN_CLK ||
 	    st->mclk_sel != AD4130_MCLK_76_8KHZ)
@@ -1843,7 +1849,11 @@  static int ad4130_setup_int_clk(struct ad4130_state *st)
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
-	return of_clk_add_provider(of_node, of_clk_src_simple_get, clk);
+	ret = of_clk_add_provider(of_node, of_clk_src_simple_get, clk);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, ad4130_clk_del_provider, of_node);
 }
 
 static int ad4130_setup(struct iio_dev *indio_dev)