mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
iio: tcs3472: power down chip on probe failure
[ Upstream commitb39f3bb9f5] 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:eb869ade30("iio: Add tcs3472 color light sensor driver") Signed-off-by: Aldo Conte <aldocontelk@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
eed69f8a10
commit
8ac30431ca
+20
-18
@@ -442,6 +442,23 @@ static const struct iio_info tcs3472_info = {
|
||||
.attrs = &tcs3472_attribute_group,
|
||||
};
|
||||
|
||||
static int tcs3472_powerdown(struct tcs3472_data *data)
|
||||
{
|
||||
int ret;
|
||||
u8 enable_mask = TCS3472_ENABLE_AEN | TCS3472_ENABLE_PON;
|
||||
|
||||
mutex_lock(&data->lock);
|
||||
|
||||
ret = i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE,
|
||||
data->enable & ~enable_mask);
|
||||
if (!ret)
|
||||
data->enable &= ~enable_mask;
|
||||
|
||||
mutex_unlock(&data->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tcs3472_probe(struct i2c_client *client)
|
||||
{
|
||||
struct tcs3472_data *data;
|
||||
@@ -515,7 +532,7 @@ static int tcs3472_probe(struct i2c_client *client)
|
||||
ret = iio_triggered_buffer_setup(indio_dev, NULL,
|
||||
tcs3472_trigger_handler, NULL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
goto error_powerdown;
|
||||
|
||||
if (client->irq) {
|
||||
ret = request_threaded_irq(client->irq, NULL,
|
||||
@@ -538,23 +555,8 @@ free_irq:
|
||||
free_irq(client->irq, indio_dev);
|
||||
buffer_cleanup:
|
||||
iio_triggered_buffer_cleanup(indio_dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tcs3472_powerdown(struct tcs3472_data *data)
|
||||
{
|
||||
int ret;
|
||||
u8 enable_mask = TCS3472_ENABLE_AEN | TCS3472_ENABLE_PON;
|
||||
|
||||
mutex_lock(&data->lock);
|
||||
|
||||
ret = i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE,
|
||||
data->enable & ~enable_mask);
|
||||
if (!ret)
|
||||
data->enable &= ~enable_mask;
|
||||
|
||||
mutex_unlock(&data->lock);
|
||||
|
||||
error_powerdown:
|
||||
tcs3472_powerdown(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user