All resources that the driver needs have managed API now. Switch to
using them to make code clearer and drop ti_ads7950_remove().
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/iio/adc/ti-ads7950.c | 66 +++++++++++++-------------------------------
1 file changed, 19 insertions(+), 47 deletions(-)
diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
index 0b98c8e7385d..234249ab76d8 100644
--- a/drivers/iio/adc/ti-ads7950.c
+++ b/drivers/iio/adc/ti-ads7950.c
@@ -506,10 +506,8 @@ static int ti_ads7950_probe(struct spi_device *spi)
spi->bits_per_word = 16;
spi->mode |= SPI_CS_WORD;
ret = spi_setup(spi);
- if (ret) {
- dev_err(&spi->dev, "Error in spi setup\n");
- return ret;
- }
+ if (ret)
+ return dev_err_probe(&spi->dev, ret, "Error in spi setup\n");
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev)
@@ -517,8 +515,6 @@ static int ti_ads7950_probe(struct spi_device *spi)
st = iio_priv(indio_dev);
- spi_set_drvdata(spi, indio_dev);
-
st->spi = spi;
info = spi_get_device_match_data(spi);
@@ -573,24 +569,22 @@ static int ti_ads7950_probe(struct spi_device *spi)
st->vref_mv = ret / 1000;
}
- ret = iio_triggered_buffer_setup(indio_dev, NULL,
- &ti_ads7950_trigger_handler, NULL);
- if (ret) {
- dev_err(&spi->dev, "Failed to setup triggered buffer\n");
- goto error_destroy_mutex;
- }
+ ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL,
+ &ti_ads7950_trigger_handler,
+ NULL);
+ if (ret)
+ return dev_err_probe(&spi->dev, ret,
+ "Failed to setup triggered buffer\n");
ret = ti_ads7950_init_hw(st);
- if (ret) {
- dev_err(&spi->dev, "Failed to init adc chip\n");
- goto error_cleanup_ring;
- }
+ if (ret)
+ return dev_err_probe(&spi->dev, ret,
+ "Failed to init adc chip\n");
- ret = iio_device_register(indio_dev);
- if (ret) {
- dev_err(&spi->dev, "Failed to register iio device\n");
- goto error_cleanup_ring;
- }
+ ret = devm_iio_device_register(&spi->dev, indio_dev);
+ if (ret)
+ return dev_err_probe(&spi->dev, ret,
+ "Failed to register iio device\n");
/* Add GPIO chip */
st->chip.label = dev_name(&st->spi->dev);
@@ -605,33 +599,12 @@ static int ti_ads7950_probe(struct spi_device *spi)
st->chip.get = ti_ads7950_get;
st->chip.set = ti_ads7950_set;
- ret = gpiochip_add_data(&st->chip, st);
- if (ret) {
- dev_err(&spi->dev, "Failed to init GPIOs\n");
- goto error_iio_device;
- }
+ ret = devm_gpiochip_add_data(&spi->dev, &st->chip, st);
+ if (ret)
+ return dev_err_probe(&spi->dev, ret,
+ "Failed to init GPIOs\n");
return 0;
-
-error_iio_device:
- iio_device_unregister(indio_dev);
-error_cleanup_ring:
- iio_triggered_buffer_cleanup(indio_dev);
-error_destroy_mutex:
- mutex_destroy(&st->slock);
-
- return ret;
-}
-
-static void ti_ads7950_remove(struct spi_device *spi)
-{
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct ti_ads7950_state *st = iio_priv(indio_dev);
-
- gpiochip_remove(&st->chip);
- iio_device_unregister(indio_dev);
- iio_triggered_buffer_cleanup(indio_dev);
- mutex_destroy(&st->slock);
}
static const struct spi_device_id ti_ads7950_id[] = {
@@ -674,7 +647,6 @@ static struct spi_driver ti_ads7950_driver = {
.of_match_table = ads7950_of_table,
},
.probe = ti_ads7950_probe,
- .remove = ti_ads7950_remove,
.id_table = ti_ads7950_id,
};
module_spi_driver(ti_ads7950_driver);
--
2.53.0.1018.g2bb0e51243-goog
On Mon, 30 Mar 2026 00:47:09 +0200, Dmitry Torokhov
<dmitry.torokhov@gmail.com> said:
> All resources that the driver needs have managed API now. Switch to
> using them to make code clearer and drop ti_ads7950_remove().
>
> Reviewed-by: David Lechner <dlechner@baylibre.com>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> -
[snip]
> -static void ti_ads7950_remove(struct spi_device *spi)
> -{
> - struct iio_dev *indio_dev = spi_get_drvdata(spi);
> - struct ti_ads7950_state *st = iio_priv(indio_dev);
> -
> - gpiochip_remove(&st->chip);
> - iio_device_unregister(indio_dev);
> - iio_triggered_buffer_cleanup(indio_dev);
> - mutex_destroy(&st->slock);
That's a functional change, there's no corresponding conversion to using
devm_mutex_init().
Bart
On March 30, 2026 2:20:33 AM PDT, Bartosz Golaszewski <brgl@kernel.org> wrote:
>On Mon, 30 Mar 2026 00:47:09 +0200, Dmitry Torokhov
><dmitry.torokhov@gmail.com> said:
>> All resources that the driver needs have managed API now. Switch to
>> using them to make code clearer and drop ti_ads7950_remove().
>>
>> Reviewed-by: David Lechner <dlechner@baylibre.com>
>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> ---
>> -
>
>[snip]
>
>> -static void ti_ads7950_remove(struct spi_device *spi)
>> -{
>> - struct iio_dev *indio_dev = spi_get_drvdata(spi);
>> - struct ti_ads7950_state *st = iio_priv(indio_dev);
>> -
>> - gpiochip_remove(&st->chip);
>> - iio_device_unregister(indio_dev);
>> - iio_triggered_buffer_cleanup(indio_dev);
>> - mutex_destroy(&st->slock);
>
>That's a functional change, there's no corresponding conversion to using
>devm_mutex_init().
devm_mutex_init() makes absolutely no sense, as well as having mutex_destroy() in remove(). The memory containing the mutex will be released right after.
--
Dmitry
On Mon, Mar 30, 2026 at 02:24:52AM -0700, Dmitry Torokhov wrote: > On March 30, 2026 2:20:33 AM PDT, Bartosz Golaszewski <brgl@kernel.org> wrote: > >On Mon, 30 Mar 2026 00:47:09 +0200, Dmitry Torokhov > ><dmitry.torokhov@gmail.com> said: ... > >> - mutex_destroy(&st->slock); > > > >That's a functional change, there's no corresponding conversion to using > >devm_mutex_init(). > > devm_mutex_init() makes absolutely no sense, as well as having > mutex_destroy() in remove(). The memory containing the mutex will be released > right after. For somebody who debugs mutexes it might make sense. So, I agree with Bart here, this needs to be addressed (and this is a used patter in IIO). -- With Best Regards, Andy Shevchenko
© 2016 - 2026 Red Hat, Inc.