staging: iio: ad7192: Use devm_* APIs and fix a memory leak
authorSachin Kamat <sachin.kamat@linaro.org>
Sat, 31 Aug 2013 17:12:00 +0000 (18:12 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sat, 7 Sep 2013 20:46:50 +0000 (21:46 +0100)
devm_* APIs are device managed and make code simpler.

The memory leak was a lack of freeing the iio_dev structure in the
remove function.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/adc/ad7192.c

index 3283e282953653eab17c098c8df6bcfe64f9d602..83bb44b381524bc448929ccab8fe29ffad92c496 100644 (file)
@@ -623,17 +623,17 @@ static int ad7192_probe(struct spi_device *spi)
                return -ENODEV;
        }
 
-       indio_dev = iio_device_alloc(sizeof(*st));
+       indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
        if (indio_dev == NULL)
                return -ENOMEM;
 
        st = iio_priv(indio_dev);
 
-       st->reg = regulator_get(&spi->dev, "vcc");
+       st->reg = devm_regulator_get(&spi->dev, "vcc");
        if (!IS_ERR(st->reg)) {
                ret = regulator_enable(st->reg);
                if (ret)
-                       goto error_put_reg;
+                       return ret;
 
                voltage_uv = regulator_get_voltage(st->reg);
        }
@@ -677,11 +677,6 @@ error_remove_trigger:
 error_disable_reg:
        if (!IS_ERR(st->reg))
                regulator_disable(st->reg);
-error_put_reg:
-       if (!IS_ERR(st->reg))
-               regulator_put(st->reg);
-
-       iio_device_free(indio_dev);
 
        return ret;
 }
@@ -694,10 +689,8 @@ static int ad7192_remove(struct spi_device *spi)
        iio_device_unregister(indio_dev);
        ad_sd_cleanup_buffer_and_trigger(indio_dev);
 
-       if (!IS_ERR(st->reg)) {
+       if (!IS_ERR(st->reg))
                regulator_disable(st->reg);
-               regulator_put(st->reg);
-       }
 
        return 0;
 }