Skip to content

Commit 8529e66

Browse files
Sachin Kamatjic23
authored andcommitted
staging: iio: tsl2x7x_core: Use devm_* APIs
devm_* APIs are device managed and make code simpler. Signed-off-by: Sachin Kamat <[email protected]> Cc: J. August Brenner <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 177e4af commit 8529e66

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

drivers/staging/iio/light/tsl2x7x_core.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
18511851
struct iio_dev *indio_dev;
18521852
struct tsl2X7X_chip *chip;
18531853

1854-
indio_dev = iio_device_alloc(sizeof(*chip));
1854+
indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip));
18551855
if (!indio_dev)
18561856
return -ENOMEM;
18571857

@@ -1862,22 +1862,21 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
18621862
ret = tsl2x7x_i2c_read(chip->client,
18631863
TSL2X7X_CHIPID, &device_id);
18641864
if (ret < 0)
1865-
goto fail1;
1865+
return ret;
18661866

18671867
if ((!tsl2x7x_device_id(&device_id, id->driver_data)) ||
18681868
(tsl2x7x_device_id(&device_id, id->driver_data) == -EINVAL)) {
18691869
dev_info(&chip->client->dev,
18701870
"%s: i2c device found does not match expected id\n",
18711871
__func__);
1872-
ret = -EINVAL;
1873-
goto fail1;
1872+
return -EINVAL;
18741873
}
18751874

18761875
ret = i2c_smbus_write_byte(clientp, (TSL2X7X_CMD_REG | TSL2X7X_CNTRL));
18771876
if (ret < 0) {
18781877
dev_err(&clientp->dev, "%s: write to cmd reg failed. err = %d\n",
18791878
__func__, ret);
1880-
goto fail1;
1879+
return ret;
18811880
}
18821881

18831882
/* ALS and PROX functions can be invoked via user space poll
@@ -1899,16 +1898,17 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
18991898
indio_dev->num_channels = chip->chip_info->chan_table_elements;
19001899

19011900
if (clientp->irq) {
1902-
ret = request_threaded_irq(clientp->irq,
1903-
NULL,
1904-
&tsl2x7x_event_handler,
1905-
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
1906-
"TSL2X7X_event",
1907-
indio_dev);
1901+
ret = devm_request_threaded_irq(&clientp->dev, clientp->irq,
1902+
NULL,
1903+
&tsl2x7x_event_handler,
1904+
IRQF_TRIGGER_RISING |
1905+
IRQF_ONESHOT,
1906+
"TSL2X7X_event",
1907+
indio_dev);
19081908
if (ret) {
19091909
dev_err(&clientp->dev,
19101910
"%s: irq request failed", __func__);
1911-
goto fail1;
1911+
return ret;
19121912
}
19131913
}
19141914

@@ -1921,20 +1921,12 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
19211921
if (ret) {
19221922
dev_err(&clientp->dev,
19231923
"%s: iio registration failed\n", __func__);
1924-
goto fail2;
1924+
return ret;
19251925
}
19261926

19271927
dev_info(&clientp->dev, "%s Light sensor found.\n", id->name);
19281928

19291929
return 0;
1930-
1931-
fail2:
1932-
if (clientp->irq)
1933-
free_irq(clientp->irq, indio_dev);
1934-
fail1:
1935-
iio_device_free(indio_dev);
1936-
1937-
return ret;
19381930
}
19391931

19401932
static int tsl2x7x_suspend(struct device *dev)
@@ -1980,10 +1972,6 @@ static int tsl2x7x_remove(struct i2c_client *client)
19801972
tsl2x7x_chip_off(indio_dev);
19811973

19821974
iio_device_unregister(indio_dev);
1983-
if (client->irq)
1984-
free_irq(client->irq, indio_dev);
1985-
1986-
iio_device_free(indio_dev);
19871975

19881976
return 0;
19891977
}

0 commit comments

Comments
 (0)