iio: adc: max11100: Use devm_ functions for rest of probe()

By using devm_add_action_or_reset() to manage the regulator disable,
it becomes simple to use managed functions for all of remove.
This simplifies error handling and allows us to drop the remove()
function entirely.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210516172520.1398835-3-jic23@kernel.org
This commit is contained in:
Jonathan Cameron 2021-05-16 18:25:14 +01:00
parent ff9111ab3e
commit 7169a78e39

View file

@ -102,6 +102,11 @@ static const struct iio_info max11100_info = {
.read_raw = max11100_read_raw,
};
static void max11100_regulator_disable(void *reg)
{
regulator_disable(reg);
}
static int max11100_probe(struct spi_device *spi)
{
int ret;
@ -112,8 +117,6 @@ static int max11100_probe(struct spi_device *spi)
if (!indio_dev)
return -ENOMEM;
spi_set_drvdata(spi, indio_dev);
state = iio_priv(indio_dev);
state->spi = spi;
@ -131,27 +134,12 @@ static int max11100_probe(struct spi_device *spi)
if (ret)
return ret;
ret = iio_device_register(indio_dev);
ret = devm_add_action_or_reset(&spi->dev, max11100_regulator_disable,
state->vref_reg);
if (ret)
goto disable_regulator;
return ret;
return 0;
disable_regulator:
regulator_disable(state->vref_reg);
return ret;
}
static int max11100_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct max11100_state *state = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
regulator_disable(state->vref_reg);
return 0;
return devm_iio_device_register(&spi->dev, indio_dev);
}
static const struct of_device_id max11100_ids[] = {
@ -166,7 +154,6 @@ static struct spi_driver max11100_driver = {
.of_match_table = max11100_ids,
},
.probe = max11100_probe,
.remove = max11100_remove,
};
module_spi_driver(max11100_driver);