From: Sachin Kamat Date: Thu, 5 Sep 2013 09:29:00 +0000 (+0100) Subject: staging: iio: tsl2x7x_core: Use devm_* APIs X-Git-Tag: v3.13-rc1~170^2~694^2~95 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8529e6673b162dcc9146238073f8632d604f8d5a;p=kernel%2Fkernel-generic.git staging: iio: tsl2x7x_core: Use devm_* APIs devm_* APIs are device managed and make code simpler. Signed-off-by: Sachin Kamat Cc: J. August Brenner Signed-off-by: Jonathan Cameron --- diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c index c99f890..aa86725 100644 --- a/drivers/staging/iio/light/tsl2x7x_core.c +++ b/drivers/staging/iio/light/tsl2x7x_core.c @@ -1851,7 +1851,7 @@ static int tsl2x7x_probe(struct i2c_client *clientp, struct iio_dev *indio_dev; struct tsl2X7X_chip *chip; - indio_dev = iio_device_alloc(sizeof(*chip)); + indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip)); if (!indio_dev) return -ENOMEM; @@ -1862,22 +1862,21 @@ static int tsl2x7x_probe(struct i2c_client *clientp, ret = tsl2x7x_i2c_read(chip->client, TSL2X7X_CHIPID, &device_id); if (ret < 0) - goto fail1; + return ret; if ((!tsl2x7x_device_id(&device_id, id->driver_data)) || (tsl2x7x_device_id(&device_id, id->driver_data) == -EINVAL)) { dev_info(&chip->client->dev, "%s: i2c device found does not match expected id\n", __func__); - ret = -EINVAL; - goto fail1; + return -EINVAL; } ret = i2c_smbus_write_byte(clientp, (TSL2X7X_CMD_REG | TSL2X7X_CNTRL)); if (ret < 0) { dev_err(&clientp->dev, "%s: write to cmd reg failed. err = %d\n", __func__, ret); - goto fail1; + return ret; } /* ALS and PROX functions can be invoked via user space poll @@ -1899,16 +1898,17 @@ static int tsl2x7x_probe(struct i2c_client *clientp, indio_dev->num_channels = chip->chip_info->chan_table_elements; if (clientp->irq) { - ret = request_threaded_irq(clientp->irq, - NULL, - &tsl2x7x_event_handler, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - "TSL2X7X_event", - indio_dev); + ret = devm_request_threaded_irq(&clientp->dev, clientp->irq, + NULL, + &tsl2x7x_event_handler, + IRQF_TRIGGER_RISING | + IRQF_ONESHOT, + "TSL2X7X_event", + indio_dev); if (ret) { dev_err(&clientp->dev, "%s: irq request failed", __func__); - goto fail1; + return ret; } } @@ -1921,20 +1921,12 @@ static int tsl2x7x_probe(struct i2c_client *clientp, if (ret) { dev_err(&clientp->dev, "%s: iio registration failed\n", __func__); - goto fail2; + return ret; } dev_info(&clientp->dev, "%s Light sensor found.\n", id->name); return 0; - -fail2: - if (clientp->irq) - free_irq(clientp->irq, indio_dev); -fail1: - iio_device_free(indio_dev); - - return ret; } static int tsl2x7x_suspend(struct device *dev) @@ -1980,10 +1972,6 @@ static int tsl2x7x_remove(struct i2c_client *client) tsl2x7x_chip_off(indio_dev); iio_device_unregister(indio_dev); - if (client->irq) - free_irq(client->irq, indio_dev); - - iio_device_free(indio_dev); return 0; }