Commit 3e70bad9 authored by Sachin Kamat's avatar Sachin Kamat Committed by Jonathan Cameron

staging: iio: ad7291: Use devm_* APIs

devm_* APIs are device managed and make code simpler.
Signed-off-by: default avatarSachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 0a2f0265
...@@ -528,21 +528,19 @@ static int ad7291_probe(struct i2c_client *client, ...@@ -528,21 +528,19 @@ static int ad7291_probe(struct i2c_client *client,
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret = 0; int ret = 0;
indio_dev = iio_device_alloc(sizeof(*chip)); indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
if (indio_dev == NULL) { if (!indio_dev)
ret = -ENOMEM; return -ENOMEM;
goto error_ret;
}
chip = iio_priv(indio_dev); chip = iio_priv(indio_dev);
if (pdata && pdata->use_external_ref) { if (pdata && pdata->use_external_ref) {
chip->reg = regulator_get(&client->dev, "vref"); chip->reg = devm_regulator_get(&client->dev, "vref");
if (IS_ERR(chip->reg)) if (IS_ERR(chip->reg))
goto error_free; return ret;
ret = regulator_enable(chip->reg); ret = regulator_enable(chip->reg);
if (ret) if (ret)
goto error_put_reg; return ret;
} }
mutex_init(&chip->state_lock); mutex_init(&chip->state_lock);
...@@ -601,12 +599,7 @@ static int ad7291_probe(struct i2c_client *client, ...@@ -601,12 +599,7 @@ static int ad7291_probe(struct i2c_client *client,
error_disable_reg: error_disable_reg:
if (chip->reg) if (chip->reg)
regulator_disable(chip->reg); regulator_disable(chip->reg);
error_put_reg:
if (chip->reg)
regulator_put(chip->reg);
error_free:
iio_device_free(indio_dev);
error_ret:
return ret; return ret;
} }
...@@ -620,12 +613,8 @@ static int ad7291_remove(struct i2c_client *client) ...@@ -620,12 +613,8 @@ static int ad7291_remove(struct i2c_client *client)
if (client->irq) if (client->irq)
free_irq(client->irq, indio_dev); free_irq(client->irq, indio_dev);
if (chip->reg) { if (chip->reg)
regulator_disable(chip->reg); regulator_disable(chip->reg);
regulator_put(chip->reg);
}
iio_device_free(indio_dev);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment