mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
iio: potentiometer: max5481: convert probe to device-managed
The change converts the probe function to use the devm_iio_device_register() function. Before calling that, we need to register an action to store the wiper back to non-volatile memory when the device is de-registered. We don't need to do this if the probe fails, because the only place where the probe can fail now is devm_iio_device_register() and that shouldn't create an IIO device (for userspace to poke at) if it fails. Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com> Link: https://lore.kernel.org/r/20210624080641.9953-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
c359a80ca2
commit
d272e0ab5f
@ -125,6 +125,11 @@ static const struct of_device_id max5481_match[] = {
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, max5481_match);
|
||||
|
||||
static void max5481_wiper_save(void *data)
|
||||
{
|
||||
max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
|
||||
}
|
||||
|
||||
static int max5481_probe(struct spi_device *spi)
|
||||
{
|
||||
struct iio_dev *indio_dev;
|
||||
@ -136,7 +141,6 @@ static int max5481_probe(struct spi_device *spi)
|
||||
if (!indio_dev)
|
||||
return -ENOMEM;
|
||||
|
||||
spi_set_drvdata(spi, indio_dev);
|
||||
data = iio_priv(indio_dev);
|
||||
|
||||
data->spi = spi;
|
||||
@ -158,18 +162,11 @@ static int max5481_probe(struct spi_device *spi)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return iio_device_register(indio_dev);
|
||||
}
|
||||
ret = devm_add_action(&spi->dev, max5481_wiper_save, data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
static int max5481_remove(struct spi_device *spi)
|
||||
{
|
||||
struct iio_dev *indio_dev = spi_get_drvdata(spi);
|
||||
struct max5481_data *data = iio_priv(indio_dev);
|
||||
|
||||
iio_device_unregister(indio_dev);
|
||||
|
||||
/* save wiper reg to NV reg */
|
||||
return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
|
||||
return devm_iio_device_register(&spi->dev, indio_dev);
|
||||
}
|
||||
|
||||
static const struct spi_device_id max5481_id_table[] = {
|
||||
@ -187,7 +184,6 @@ static struct spi_driver max5481_driver = {
|
||||
.of_match_table = max5481_match,
|
||||
},
|
||||
.probe = max5481_probe,
|
||||
.remove = max5481_remove,
|
||||
.id_table = max5481_id_table,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user