iio:mcp4725: Use devm_iio_device_alloc
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
2669d723ac
commit
b6ff86f3f5
|
@ -292,15 +292,12 @@ static int mcp4725_probe(struct i2c_client *client,
|
||||||
|
|
||||||
if (!platform_data || !platform_data->vref_mv) {
|
if (!platform_data || !platform_data->vref_mv) {
|
||||||
dev_err(&client->dev, "invalid platform data");
|
dev_err(&client->dev, "invalid platform data");
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
indio_dev = iio_device_alloc(sizeof(*data));
|
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
|
||||||
if (indio_dev == NULL) {
|
if (indio_dev == NULL)
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
data = iio_priv(indio_dev);
|
data = iio_priv(indio_dev);
|
||||||
i2c_set_clientdata(client, indio_dev);
|
i2c_set_clientdata(client, indio_dev);
|
||||||
data->client = client;
|
data->client = client;
|
||||||
|
@ -317,7 +314,7 @@ static int mcp4725_probe(struct i2c_client *client,
|
||||||
err = i2c_master_recv(client, inbuf, 3);
|
err = i2c_master_recv(client, inbuf, 3);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&client->dev, "failed to read DAC value");
|
dev_err(&client->dev, "failed to read DAC value");
|
||||||
goto exit_free_device;
|
return err;
|
||||||
}
|
}
|
||||||
pd = (inbuf[0] >> 1) & 0x3;
|
pd = (inbuf[0] >> 1) & 0x3;
|
||||||
data->powerdown = pd > 0 ? true : false;
|
data->powerdown = pd > 0 ? true : false;
|
||||||
|
@ -326,25 +323,16 @@ static int mcp4725_probe(struct i2c_client *client,
|
||||||
|
|
||||||
err = iio_device_register(indio_dev);
|
err = iio_device_register(indio_dev);
|
||||||
if (err)
|
if (err)
|
||||||
goto exit_free_device;
|
return err;
|
||||||
|
|
||||||
dev_info(&client->dev, "MCP4725 DAC registered\n");
|
dev_info(&client->dev, "MCP4725 DAC registered\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
exit_free_device:
|
|
||||||
iio_device_free(indio_dev);
|
|
||||||
exit:
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcp4725_remove(struct i2c_client *client)
|
static int mcp4725_remove(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
iio_device_unregister(i2c_get_clientdata(client));
|
||||||
|
|
||||||
iio_device_unregister(indio_dev);
|
|
||||||
iio_device_free(indio_dev);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue