Skip to content

Commit 0eab65c

Browse files
Sachin Kamatjic23
authored andcommitted
staging: iio: ad7746: Use devm_iio_device_alloc
Using devm_iio_device_alloc makes code simpler. Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 538ee7c commit 0eab65c

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

‎drivers/staging/iio/cdc/ad7746.c‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,9 @@ static int ad7746_probe(struct i2c_client *client,
699699
int ret = 0;
700700
unsigned char regval = 0;
701701

702-
indio_dev = iio_device_alloc(sizeof(*chip));
703-
if (indio_dev == NULL) {
704-
ret = -ENOMEM;
705-
goto error_ret;
706-
}
702+
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
703+
if (!indio_dev)
704+
return -ENOMEM;
707705
chip = iio_priv(indio_dev);
708706
/* this is only used for device removal purposes */
709707
i2c_set_clientdata(client, indio_dev);
@@ -748,28 +746,22 @@ static int ad7746_probe(struct i2c_client *client,
748746
ret = i2c_smbus_write_byte_data(chip->client,
749747
AD7746_REG_EXC_SETUP, regval);
750748
if (ret < 0)
751-
goto error_free_dev;
749+
return ret;
752750

753751
ret = iio_device_register(indio_dev);
754752
if (ret)
755-
goto error_free_dev;
753+
return ret;
756754

757755
dev_info(&client->dev, "%s capacitive sensor registered\n", id->name);
758756

759757
return 0;
760-
761-
error_free_dev:
762-
iio_device_free(indio_dev);
763-
error_ret:
764-
return ret;
765758
}
766759

767760
static int ad7746_remove(struct i2c_client *client)
768761
{
769762
struct iio_dev *indio_dev = i2c_get_clientdata(client);
770763

771764
iio_device_unregister(indio_dev);
772-
iio_device_free(indio_dev);
773765

774766
return 0;
775767
}

0 commit comments

Comments
 (0)