diff options
Diffstat (limited to 'drivers/iio/adc/ad7887.c')
-rw-r--r-- | drivers/iio/adc/ad7887.c | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c index dd15a5b0f701..9dd077b78759 100644 --- a/drivers/iio/adc/ad7887.c +++ b/drivers/iio/adc/ad7887.c | |||
@@ -237,25 +237,24 @@ static int ad7887_probe(struct spi_device *spi) | |||
237 | { | 237 | { |
238 | struct ad7887_platform_data *pdata = spi->dev.platform_data; | 238 | struct ad7887_platform_data *pdata = spi->dev.platform_data; |
239 | struct ad7887_state *st; | 239 | struct ad7887_state *st; |
240 | struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); | 240 | struct iio_dev *indio_dev; |
241 | uint8_t mode; | 241 | uint8_t mode; |
242 | int ret; | 242 | int ret; |
243 | 243 | ||
244 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); | ||
244 | if (indio_dev == NULL) | 245 | if (indio_dev == NULL) |
245 | return -ENOMEM; | 246 | return -ENOMEM; |
246 | 247 | ||
247 | st = iio_priv(indio_dev); | 248 | st = iio_priv(indio_dev); |
248 | 249 | ||
249 | if (!pdata || !pdata->use_onchip_ref) { | 250 | if (!pdata || !pdata->use_onchip_ref) { |
250 | st->reg = regulator_get(&spi->dev, "vref"); | 251 | st->reg = devm_regulator_get(&spi->dev, "vref"); |
251 | if (IS_ERR(st->reg)) { | 252 | if (IS_ERR(st->reg)) |
252 | ret = PTR_ERR(st->reg); | 253 | return PTR_ERR(st->reg); |
253 | goto error_free; | ||
254 | } | ||
255 | 254 | ||
256 | ret = regulator_enable(st->reg); | 255 | ret = regulator_enable(st->reg); |
257 | if (ret) | 256 | if (ret) |
258 | goto error_put_reg; | 257 | return ret; |
259 | } | 258 | } |
260 | 259 | ||
261 | st->chip_info = | 260 | st->chip_info = |
@@ -331,11 +330,6 @@ error_unregister_ring: | |||
331 | error_disable_reg: | 330 | error_disable_reg: |
332 | if (st->reg) | 331 | if (st->reg) |
333 | regulator_disable(st->reg); | 332 | regulator_disable(st->reg); |
334 | error_put_reg: | ||
335 | if (st->reg) | ||
336 | regulator_put(st->reg); | ||
337 | error_free: | ||
338 | iio_device_free(indio_dev); | ||
339 | 333 | ||
340 | return ret; | 334 | return ret; |
341 | } | 335 | } |
@@ -347,11 +341,8 @@ static int ad7887_remove(struct spi_device *spi) | |||
347 | 341 | ||
348 | iio_device_unregister(indio_dev); | 342 | iio_device_unregister(indio_dev); |
349 | iio_triggered_buffer_cleanup(indio_dev); | 343 | iio_triggered_buffer_cleanup(indio_dev); |
350 | if (st->reg) { | 344 | if (st->reg) |
351 | regulator_disable(st->reg); | 345 | regulator_disable(st->reg); |
352 | regulator_put(st->reg); | ||
353 | } | ||
354 | iio_device_free(indio_dev); | ||
355 | 346 | ||
356 | return 0; | 347 | return 0; |
357 | } | 348 | } |