* [PATCH] iio: light: tsl4531: Use device-managed cleanup in probe
@ 2026-12-01 16:22 Vineet Thakran
2026-12-01 18:54 ` Arnav Kapoor
2026-12-03 16:40 ` Andy Shevchenko
0 siblings, 2 replies; 3+ messages in thread
From: Vineet Thakran @ 2026-12-01 16:22 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
Vineet Thakran
The sensor is switched to normal mode during probe, but if a later step
fails (writing the config register or registering the IIO device), probe
returns an error and the sensor is left powered on, because remove() is
not called for a failed probe.
Register a devm action that powers down the sensor right after it is
enabled, and use devm_iio_device_register(). This also lets the driver
drop its remove() callback and the now unused i2c_set_clientdata() call,
while keeping the same teardown order: unregister first, then power down.
Compile-tested only; no hardware available.
Fixes: aab9ba7eb263 ("iio: Add tsl4531 ambient light sensor driver")
Signed-off-by: Vineet Thakran <vineet789thakran@gmail.com>
---
drivers/iio/light/tsl4531.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c
index 2f91ed8a9..463f52d9c 100644
--- a/drivers/iio/light/tsl4531.c
+++ b/drivers/iio/light/tsl4531.c
@@ -160,6 +160,17 @@ static int tsl4531_check_id(struct i2c_client *client)
}
}
+static int tsl4531_powerdown(struct i2c_client *client)
+{
+ return i2c_smbus_write_byte_data(client, TSL4531_CONTROL,
+ TSL4531_MODE_POWERDOWN);
+}
+
+static void tsl4531_powerdown_action(void *client)
+{
+ tsl4531_powerdown(client);
+}
+
static int tsl4531_probe(struct i2c_client *client)
{
struct tsl4531_data *data;
@@ -171,7 +182,6 @@ static int tsl4531_probe(struct i2c_client *client)
return -ENOMEM;
data = iio_priv(indio_dev);
- i2c_set_clientdata(client, indio_dev);
data->client = client;
mutex_init(&data->lock);
@@ -186,6 +196,11 @@ static int tsl4531_probe(struct i2c_client *client)
if (ret < 0)
return ret;
+ ret = devm_add_action_or_reset(&client->dev, tsl4531_powerdown_action,
+ client);
+ if (ret)
+ return ret;
+
ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONFIG,
TSL4531_TCNTRL_400MS);
if (ret < 0)
@@ -197,19 +212,7 @@ static int tsl4531_probe(struct i2c_client *client)
indio_dev->name = TSL4531_DRV_NAME;
indio_dev->modes = INDIO_DIRECT_MODE;
- return iio_device_register(indio_dev);
-}
-
-static int tsl4531_powerdown(struct i2c_client *client)
-{
- return i2c_smbus_write_byte_data(client, TSL4531_CONTROL,
- TSL4531_MODE_POWERDOWN);
-}
-
-static void tsl4531_remove(struct i2c_client *client)
-{
- iio_device_unregister(i2c_get_clientdata(client));
- tsl4531_powerdown(client);
+ return devm_iio_device_register(&client->dev, indio_dev);
}
static int tsl4531_suspend(struct device *dev)
@@ -238,7 +241,6 @@ static struct i2c_driver tsl4531_driver = {
.pm = pm_sleep_ptr(&tsl4531_pm_ops),
},
.probe = tsl4531_probe,
- .remove = tsl4531_remove,
.id_table = tsl4531_id,
};
base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: light: tsl4531: Use device-managed cleanup in probe
2026-12-01 16:22 [PATCH] iio: light: tsl4531: Use device-managed cleanup in probe Vineet Thakran
@ 2026-12-01 18:54 ` Arnav Kapoor
2026-12-03 16:40 ` Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Arnav Kapoor @ 2026-12-01 18:54 UTC (permalink / raw)
To: Vineet Thakran
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio
On Tue, Dec 01, 2026 at 04:22:17PM +0000, Vineet Thakran wrote:
> The sensor is switched to normal mode during probe, but if a later step
> fails (writing the config register or registering the IIO device), probe
> returns an error and the sensor is left powered on, because remove() is
> not called for a failed probe.
Reviewed-by: Arnav Kapoor <kapoorarnav43@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: light: tsl4531: Use device-managed cleanup in probe
2026-12-01 16:22 [PATCH] iio: light: tsl4531: Use device-managed cleanup in probe Vineet Thakran
2026-12-01 18:54 ` Arnav Kapoor
@ 2026-12-03 16:40 ` Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-12-03 16:40 UTC (permalink / raw)
To: Vineet Thakran
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio
On Tue, Dec 01, 2026 at 04:22:17PM +0000, Vineet Thakran wrote:
> The sensor is switched to normal mode during probe, but if a later step
> fails (writing the config register or registering the IIO device), probe
> returns an error and the sensor is left powered on, because remove() is
> not called for a failed probe.
>
> Register a devm action that powers down the sensor right after it is
> enabled, and use devm_iio_device_register(). This also lets the driver
> drop its remove() callback and the now unused i2c_set_clientdata() call,
> while keeping the same teardown order: unregister first, then power down.
>
> Compile-tested only; no hardware available.
...
> + ret = devm_add_action_or_reset(&client->dev, tsl4531_powerdown_action,
> + client);
With
struct device *dev = &client->dev;
at the top of the function this becomes
ret = devm_add_action_or_reset(dev, tsl4531_powerdown_action, client);
> + if (ret)
> + return ret;
...
> + return devm_iio_device_register(&client->dev, indio_dev);
And this respectively
return devm_iio_device_register(dev, indio_dev);
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 16:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:22 [PATCH] iio: light: tsl4531: Use device-managed cleanup in probe Vineet Thakran
2026-12-01 18:54 ` Arnav Kapoor
2026-12-03 16:40 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox