Commit a726dea5 authored by Sachin Kamat's avatar Sachin Kamat Committed by Jonathan Cameron

iio: adc: mcp320x: Use devm_* APIs

devm_* APIs are device managed and make code simpler.
Signed-off-by: default avatarSachin Kamat <sachin.kamat@linaro.org>
Cc: Oskar Andero <oskar.andero@gmail.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 8483aa5e
...@@ -169,7 +169,7 @@ static int mcp320x_probe(struct spi_device *spi) ...@@ -169,7 +169,7 @@ static int mcp320x_probe(struct spi_device *spi)
const struct mcp3208_chip_info *chip_info; const struct mcp3208_chip_info *chip_info;
int ret; int ret;
indio_dev = iio_device_alloc(sizeof(*adc)); indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
...@@ -193,15 +193,13 @@ static int mcp320x_probe(struct spi_device *spi) ...@@ -193,15 +193,13 @@ static int mcp320x_probe(struct spi_device *spi)
spi_message_init_with_transfers(&adc->msg, adc->transfer, spi_message_init_with_transfers(&adc->msg, adc->transfer,
ARRAY_SIZE(adc->transfer)); ARRAY_SIZE(adc->transfer));
adc->reg = regulator_get(&spi->dev, "vref"); adc->reg = devm_regulator_get(&spi->dev, "vref");
if (IS_ERR(adc->reg)) { if (IS_ERR(adc->reg))
ret = PTR_ERR(adc->reg); return PTR_ERR(adc->reg);
goto iio_free;
}
ret = regulator_enable(adc->reg); ret = regulator_enable(adc->reg);
if (ret < 0) if (ret < 0)
goto reg_free; return ret;
mutex_init(&adc->lock); mutex_init(&adc->lock);
...@@ -213,10 +211,6 @@ static int mcp320x_probe(struct spi_device *spi) ...@@ -213,10 +211,6 @@ static int mcp320x_probe(struct spi_device *spi)
reg_disable: reg_disable:
regulator_disable(adc->reg); regulator_disable(adc->reg);
reg_free:
regulator_put(adc->reg);
iio_free:
iio_device_free(indio_dev);
return ret; return ret;
} }
...@@ -228,8 +222,6 @@ static int mcp320x_remove(struct spi_device *spi) ...@@ -228,8 +222,6 @@ static int mcp320x_remove(struct spi_device *spi)
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
regulator_disable(adc->reg); regulator_disable(adc->reg);
regulator_put(adc->reg);
iio_device_free(indio_dev);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment