mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
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:
parent
ff9111ab3e
commit
7169a78e39
1 changed files with 9 additions and 22 deletions
|
@ -102,6 +102,11 @@ static const struct iio_info max11100_info = {
|
||||||
.read_raw = max11100_read_raw,
|
.read_raw = max11100_read_raw,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void max11100_regulator_disable(void *reg)
|
||||||
|
{
|
||||||
|
regulator_disable(reg);
|
||||||
|
}
|
||||||
|
|
||||||
static int max11100_probe(struct spi_device *spi)
|
static int max11100_probe(struct spi_device *spi)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -112,8 +117,6 @@ static int max11100_probe(struct spi_device *spi)
|
||||||
if (!indio_dev)
|
if (!indio_dev)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
spi_set_drvdata(spi, indio_dev);
|
|
||||||
|
|
||||||
state = iio_priv(indio_dev);
|
state = iio_priv(indio_dev);
|
||||||
state->spi = spi;
|
state->spi = spi;
|
||||||
|
|
||||||
|
@ -131,27 +134,12 @@ static int max11100_probe(struct spi_device *spi)
|
||||||
if (ret)
|
if (ret)
|
||||||
return 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)
|
if (ret)
|
||||||
goto disable_regulator;
|
return ret;
|
||||||
|
|
||||||
return 0;
|
return devm_iio_device_register(&spi->dev, indio_dev);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct of_device_id max11100_ids[] = {
|
static const struct of_device_id max11100_ids[] = {
|
||||||
|
@ -166,7 +154,6 @@ static struct spi_driver max11100_driver = {
|
||||||
.of_match_table = max11100_ids,
|
.of_match_table = max11100_ids,
|
||||||
},
|
},
|
||||||
.probe = max11100_probe,
|
.probe = max11100_probe,
|
||||||
.remove = max11100_remove,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module_spi_driver(max11100_driver);
|
module_spi_driver(max11100_driver);
|
||||||
|
|
Loading…
Reference in a new issue