Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: ad4130: Make sure clock provider gets removed

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>
Link: https://lore.kernel.org/r/20230414150702.518441-1-lars@metafoo.de
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
28f73ded 265c82ea

+11 -1
+11 -1
drivers/iio/adc/ad4130.c
··· 1817 1817 .unprepare = ad4130_int_clk_unprepare, 1818 1818 }; 1819 1819 1820 + static void ad4130_clk_del_provider(void *of_node) 1821 + { 1822 + of_clk_del_provider(of_node); 1823 + } 1824 + 1820 1825 static int ad4130_setup_int_clk(struct ad4130_state *st) 1821 1826 { 1822 1827 struct device *dev = &st->spi->dev; ··· 1829 1824 struct clk_init_data init; 1830 1825 const char *clk_name; 1831 1826 struct clk *clk; 1827 + int ret; 1832 1828 1833 1829 if (st->int_pin_sel == AD4130_INT_PIN_CLK || 1834 1830 st->mclk_sel != AD4130_MCLK_76_8KHZ) ··· 1849 1843 if (IS_ERR(clk)) 1850 1844 return PTR_ERR(clk); 1851 1845 1852 - return of_clk_add_provider(of_node, of_clk_src_simple_get, clk); 1846 + ret = of_clk_add_provider(of_node, of_clk_src_simple_get, clk); 1847 + if (ret) 1848 + return ret; 1849 + 1850 + return devm_add_action_or_reset(dev, ad4130_clk_del_provider, of_node); 1853 1851 } 1854 1852 1855 1853 static int ad4130_setup(struct iio_dev *indio_dev)