staging: iio: ad799x_core: Use devm_* APIs
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:50:34 +0000 (21:50 +0100)
devm_* APIs are device managed and make code simpler.

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

index 2b2049c8bc6ba969896168f6b22b58ed7336afcc..3f5142b284d1cbb66e213be9528ab56a904130f9 100644 (file)
@@ -586,8 +586,9 @@ static int ad799x_probe(struct i2c_client *client,
        int ret;
        struct ad799x_platform_data *pdata = client->dev.platform_data;
        struct ad799x_state *st;
-       struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
+       struct iio_dev *indio_dev;
 
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
        if (indio_dev == NULL)
                return -ENOMEM;
 
@@ -606,11 +607,11 @@ static int ad799x_probe(struct i2c_client *client,
 
        st->int_vref_mv = pdata->vref_mv;
 
-       st->reg = regulator_get(&client->dev, "vcc");
+       st->reg = devm_regulator_get(&client->dev, "vcc");
        if (!IS_ERR(st->reg)) {
                ret = regulator_enable(st->reg);
                if (ret)
-                       goto error_put_reg;
+                       return ret;
        }
        st->client = client;
 
@@ -650,10 +651,6 @@ error_cleanup_ring:
 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;
 }
@@ -668,12 +665,9 @@ static int ad799x_remove(struct i2c_client *client)
                free_irq(client->irq, indio_dev);
 
        ad799x_ring_cleanup(indio_dev);
-       if (!IS_ERR(st->reg)) {
+       if (!IS_ERR(st->reg))
                regulator_disable(st->reg);
-               regulator_put(st->reg);
-       }
        kfree(st->rx_buf);
-       iio_device_free(indio_dev);
 
        return 0;
 }