[PATCH v7 06/12] media: tw9900: power off the device on remove if still active
From: Matthew Laux
Date: Fri Nov 20 2026 - 22:56:27 EST
tw9900_remove() and the probe error path only call pm_runtime_disable(),
which does not invoke the runtime suspend callback. If the device is
active at that point, e.g. when a USB bridge is unplugged while streaming,
the vdd regulator is left enabled and devres then puts it, which triggers:
WARNING: drivers/regulator/core.c:2657 at regulator_put+0x61/0x70
...
release_nodes+0x46/0xd0
devres_release_group+0x11f/0x150
i2c_device_remove+0x41/0xb0
Suspend the device manually when it is not already suspended, then mark
it suspended, following the usual pattern for sensor drivers.
Fixes: 918b14a26b12 ("media: i2c: Introduce a driver for the Techwell TW9900 decoder")
Signed-off-by: Matthew Laux <matthew.laux@xxxxxxxxx>
---
drivers/media/i2c/tw9900.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c
index 6309d9eda243..585509c1b41d 100644
--- a/drivers/media/i2c/tw9900.c
+++ b/drivers/media/i2c/tw9900.c
@@ -699,6 +699,14 @@ static int tw9900_runtime_suspend(struct device *dev)
return 0;
}
+static void tw9900_pm_cleanup(struct device *dev)
+{
+ pm_runtime_disable(dev);
+ if (!pm_runtime_status_suspended(dev))
+ tw9900_runtime_suspend(dev);
+ pm_runtime_set_suspended(dev);
+}
+
static int tw9900_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
@@ -778,7 +786,7 @@ static int tw9900_probe(struct i2c_client *client)
return 0;
err_disable_pm:
- pm_runtime_disable(dev);
+ tw9900_pm_cleanup(dev);
media_entity_cleanup(&tw9900->subdev.entity);
err_free_handler:
v4l2_ctrl_handler_free(hdl);
@@ -797,7 +805,7 @@ static void tw9900_remove(struct i2c_client *client)
media_entity_cleanup(&sd->entity);
v4l2_ctrl_handler_free(sd->ctrl_handler);
- pm_runtime_disable(&client->dev);
+ tw9900_pm_cleanup(&client->dev);
mutex_destroy(&tw9900->mutex);
}
--
2.47.3