]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: amplifiers: ad8366: refactor device resource management
authorRodrigo Alencar <rodrigo.alencar@analog.com>
Mon, 16 Feb 2026 17:10:50 +0000 (17:10 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 23 Feb 2026 21:00:57 +0000 (21:00 +0000)
Adhere modern device resource management with the following:
- Voltage regulator managed and enabled internally;
- IIO device registration handled with devm_iio_device_register();
- removal of goto's from the probe function;
- ad8366_remove() removed as it is not needed anymore;

With the drop of goto's dev_err_probe() is used to report probe errors.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/amplifiers/ad8366.c

index 6466f3eb6bbccdd7de72521347775753db8795be..e8c80551d524eae74845f607923724c59310f05f 100644 (file)
@@ -43,7 +43,6 @@ struct ad8366_info {
 
 struct ad8366_state {
        struct spi_device       *spi;
-       struct regulator        *reg;
        struct mutex            lock; /* protect sensor state */
        struct gpio_desc        *reset_gpio;
        unsigned char           ch[2];
@@ -263,14 +262,10 @@ static int ad8366_probe(struct spi_device *spi)
        if (ret)
                return ret;
 
-       st->reg = devm_regulator_get(&spi->dev, "vcc");
-       if (!IS_ERR(st->reg)) {
-               ret = regulator_enable(st->reg);
-               if (ret)
-                       return ret;
-       }
+       ret = devm_regulator_get_enable(dev, "vcc");
+       if (ret)
+               return dev_err_probe(dev, ret, "Failed to get regulator\n");
 
-       spi_set_drvdata(spi, indio_dev);
        st->spi = spi;
        st->type = spi_get_device_id(spi)->driver_data;
 
@@ -284,17 +279,15 @@ static int ad8366_probe(struct spi_device *spi)
        case ID_HMC792:
        case ID_HMC1119:
                st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
-               if (IS_ERR(st->reset_gpio)) {
-                       ret = PTR_ERR(st->reset_gpio);
-                       goto error_disable_reg;
-               }
+               if (IS_ERR(st->reset_gpio))
+                       return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
+                                            "Failed to get reset gpio\n");
+
                indio_dev->channels = ada4961_channels;
                indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
                break;
        default:
-               dev_err(&spi->dev, "Invalid device ID\n");
-               ret = -EINVAL;
-               goto error_disable_reg;
+               return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
        }
 
        st->info = &ad8366_infos[st->type];
@@ -304,31 +297,9 @@ static int ad8366_probe(struct spi_device *spi)
 
        ret = ad8366_write(indio_dev, 0, 0);
        if (ret < 0)
-               goto error_disable_reg;
-
-       ret = iio_device_register(indio_dev);
-       if (ret)
-               goto error_disable_reg;
-
-       return 0;
-
-error_disable_reg:
-       if (!IS_ERR(st->reg))
-               regulator_disable(st->reg);
-
-       return ret;
-}
-
-static void ad8366_remove(struct spi_device *spi)
-{
-       struct iio_dev *indio_dev = spi_get_drvdata(spi);
-       struct ad8366_state *st = iio_priv(indio_dev);
-       struct regulator *reg = st->reg;
-
-       iio_device_unregister(indio_dev);
+               return dev_err_probe(dev, ret, "failed to write initial gain\n");
 
-       if (!IS_ERR(reg))
-               regulator_disable(reg);
+       return devm_iio_device_register(dev, indio_dev);
 }
 
 static const struct spi_device_id ad8366_id[] = {
@@ -346,7 +317,6 @@ static struct spi_driver ad8366_driver = {
                .name   = KBUILD_MODNAME,
        },
        .probe          = ad8366_probe,
-       .remove         = ad8366_remove,
        .id_table       = ad8366_id,
 };