Skip to content

Commit b39f3bb

Browse files
aldocontelkjic23
authored andcommitted
iio: tcs3472: power down chip on probe failure
If tcs3472_probe() fails after enabling the chip (by writing PON | AEN to the ENABLE register), the error paths return without powering down the device. Add an 'error_powerdown' label at the end of the cleanup chain that calls tcs3472_powerdown() to power down the chip. The existing label cascade is rerouted to fall through to the new label. Move tcs3472_powerdown() above tcs3472_probe() so the probe can call it without a forward declaration. Found by code inspection while reviewing the probe error paths in preparation for the devm_ conversion. Fixes: eb869ad ("iio: Add tcs3472 color light sensor driver") Signed-off-by: Aldo Conte <aldocontelk@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent f1cb3d3 commit b39f3bb

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

drivers/iio/light/tcs3472.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,23 @@ static const struct iio_info tcs3472_info = {
440440
.attrs = &tcs3472_attribute_group,
441441
};
442442

443+
static int tcs3472_powerdown(struct tcs3472_data *data)
444+
{
445+
int ret;
446+
u8 enable_mask = TCS3472_ENABLE_AEN | TCS3472_ENABLE_PON;
447+
448+
mutex_lock(&data->lock);
449+
450+
ret = i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE,
451+
data->enable & ~enable_mask);
452+
if (!ret)
453+
data->enable &= ~enable_mask;
454+
455+
mutex_unlock(&data->lock);
456+
457+
return ret;
458+
}
459+
443460
static int tcs3472_probe(struct i2c_client *client)
444461
{
445462
struct tcs3472_data *data;
@@ -513,7 +530,7 @@ static int tcs3472_probe(struct i2c_client *client)
513530
ret = iio_triggered_buffer_setup(indio_dev, NULL,
514531
tcs3472_trigger_handler, NULL);
515532
if (ret < 0)
516-
return ret;
533+
goto error_powerdown;
517534

518535
if (client->irq) {
519536
ret = request_threaded_irq(client->irq, NULL,
@@ -536,23 +553,8 @@ static int tcs3472_probe(struct i2c_client *client)
536553
free_irq(client->irq, indio_dev);
537554
buffer_cleanup:
538555
iio_triggered_buffer_cleanup(indio_dev);
539-
return ret;
540-
}
541-
542-
static int tcs3472_powerdown(struct tcs3472_data *data)
543-
{
544-
int ret;
545-
u8 enable_mask = TCS3472_ENABLE_AEN | TCS3472_ENABLE_PON;
546-
547-
mutex_lock(&data->lock);
548-
549-
ret = i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE,
550-
data->enable & ~enable_mask);
551-
if (!ret)
552-
data->enable &= ~enable_mask;
553-
554-
mutex_unlock(&data->lock);
555-
556+
error_powerdown:
557+
tcs3472_powerdown(data);
556558
return ret;
557559
}
558560

0 commit comments

Comments
 (0)