aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/mcp320x.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/adc/mcp320x.c')
-rw-r--r--drivers/iio/adc/mcp320x.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
index ebc015922a79..28a086e48776 100644
--- a/drivers/iio/adc/mcp320x.c
+++ b/drivers/iio/adc/mcp320x.c
@@ -169,7 +169,7 @@ static int mcp320x_probe(struct spi_device *spi)
169 const struct mcp3208_chip_info *chip_info; 169 const struct mcp3208_chip_info *chip_info;
170 int ret; 170 int ret;
171 171
172 indio_dev = iio_device_alloc(sizeof(*adc)); 172 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
173 if (!indio_dev) 173 if (!indio_dev)
174 return -ENOMEM; 174 return -ENOMEM;
175 175
@@ -193,15 +193,13 @@ static int mcp320x_probe(struct spi_device *spi)
193 spi_message_init_with_transfers(&adc->msg, adc->transfer, 193 spi_message_init_with_transfers(&adc->msg, adc->transfer,
194 ARRAY_SIZE(adc->transfer)); 194 ARRAY_SIZE(adc->transfer));
195 195
196 adc->reg = regulator_get(&spi->dev, "vref"); 196 adc->reg = devm_regulator_get(&spi->dev, "vref");
197 if (IS_ERR(adc->reg)) { 197 if (IS_ERR(adc->reg))
198 ret = PTR_ERR(adc->reg); 198 return PTR_ERR(adc->reg);
199 goto iio_free;
200 }
201 199
202 ret = regulator_enable(adc->reg); 200 ret = regulator_enable(adc->reg);
203 if (ret < 0) 201 if (ret < 0)
204 goto reg_free; 202 return ret;
205 203
206 mutex_init(&adc->lock); 204 mutex_init(&adc->lock);
207 205
@@ -213,10 +211,6 @@ static int mcp320x_probe(struct spi_device *spi)
213 211
214reg_disable: 212reg_disable:
215 regulator_disable(adc->reg); 213 regulator_disable(adc->reg);
216reg_free:
217 regulator_put(adc->reg);
218iio_free:
219 iio_device_free(indio_dev);
220 214
221 return ret; 215 return ret;
222} 216}
@@ -228,8 +222,6 @@ static int mcp320x_remove(struct spi_device *spi)
228 222
229 iio_device_unregister(indio_dev); 223 iio_device_unregister(indio_dev);
230 regulator_disable(adc->reg); 224 regulator_disable(adc->reg);
231 regulator_put(adc->reg);
232 iio_device_free(indio_dev);
233 225
234 return 0; 226 return 0;
235} 227}