aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/dac/ad7303.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/dac/ad7303.c')
-rw-r--r--drivers/iio/dac/ad7303.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/drivers/iio/dac/ad7303.c b/drivers/iio/dac/ad7303.c
index d546f50f9258..ed2d276477bd 100644
--- a/drivers/iio/dac/ad7303.c
+++ b/drivers/iio/dac/ad7303.c
@@ -203,7 +203,7 @@ static int ad7303_probe(struct spi_device *spi)
203 bool ext_ref; 203 bool ext_ref;
204 int ret; 204 int ret;
205 205
206 indio_dev = iio_device_alloc(sizeof(*st)); 206 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
207 if (indio_dev == NULL) 207 if (indio_dev == NULL)
208 return -ENOMEM; 208 return -ENOMEM;
209 209
@@ -212,15 +212,13 @@ static int ad7303_probe(struct spi_device *spi)
212 212
213 st->spi = spi; 213 st->spi = spi;
214 214
215 st->vdd_reg = regulator_get(&spi->dev, "Vdd"); 215 st->vdd_reg = devm_regulator_get(&spi->dev, "Vdd");
216 if (IS_ERR(st->vdd_reg)) { 216 if (IS_ERR(st->vdd_reg))
217 ret = PTR_ERR(st->vdd_reg); 217 return PTR_ERR(st->vdd_reg);
218 goto err_free;
219 }
220 218
221 ret = regulator_enable(st->vdd_reg); 219 ret = regulator_enable(st->vdd_reg);
222 if (ret) 220 if (ret)
223 goto err_put_vdd_reg; 221 return ret;
224 222
225 if (spi->dev.of_node) { 223 if (spi->dev.of_node) {
226 ext_ref = of_property_read_bool(spi->dev.of_node, 224 ext_ref = of_property_read_bool(spi->dev.of_node,
@@ -234,7 +232,7 @@ static int ad7303_probe(struct spi_device *spi)
234 } 232 }
235 233
236 if (ext_ref) { 234 if (ext_ref) {
237 st->vref_reg = regulator_get(&spi->dev, "REF"); 235 st->vref_reg = devm_regulator_get(&spi->dev, "REF");
238 if (IS_ERR(st->vref_reg)) { 236 if (IS_ERR(st->vref_reg)) {
239 ret = PTR_ERR(st->vref_reg); 237 ret = PTR_ERR(st->vref_reg);
240 goto err_disable_vdd_reg; 238 goto err_disable_vdd_reg;
@@ -242,7 +240,7 @@ static int ad7303_probe(struct spi_device *spi)
242 240
243 ret = regulator_enable(st->vref_reg); 241 ret = regulator_enable(st->vref_reg);
244 if (ret) 242 if (ret)
245 goto err_put_vref_reg; 243 goto err_disable_vdd_reg;
246 244
247 st->config |= AD7303_CFG_EXTERNAL_VREF; 245 st->config |= AD7303_CFG_EXTERNAL_VREF;
248 } 246 }
@@ -263,16 +261,8 @@ static int ad7303_probe(struct spi_device *spi)
263err_disable_vref_reg: 261err_disable_vref_reg:
264 if (st->vref_reg) 262 if (st->vref_reg)
265 regulator_disable(st->vref_reg); 263 regulator_disable(st->vref_reg);
266err_put_vref_reg:
267 if (st->vref_reg)
268 regulator_put(st->vref_reg);
269err_disable_vdd_reg: 264err_disable_vdd_reg:
270 regulator_disable(st->vdd_reg); 265 regulator_disable(st->vdd_reg);
271err_put_vdd_reg:
272 regulator_put(st->vdd_reg);
273err_free:
274 iio_device_free(indio_dev);
275
276 return ret; 266 return ret;
277} 267}
278 268
@@ -283,14 +273,9 @@ static int ad7303_remove(struct spi_device *spi)
283 273
284 iio_device_unregister(indio_dev); 274 iio_device_unregister(indio_dev);
285 275
286 if (st->vref_reg) { 276 if (st->vref_reg)
287 regulator_disable(st->vref_reg); 277 regulator_disable(st->vref_reg);
288 regulator_put(st->vref_reg);
289 }
290 regulator_disable(st->vdd_reg); 278 regulator_disable(st->vdd_reg);
291 regulator_put(st->vdd_reg);
292
293 iio_device_free(indio_dev);
294 279
295 return 0; 280 return 0;
296} 281}