[PATCH v2 12/16] media: i2c: tw9900: power off the decoder on remove

From: Cong Nguyen

Date: Mon Nov 23 2026 - 10:40:49 EST


tw9900_probe() ends with the device runtime suspended, and
tw9900_s_stream() takes a runtime PM reference with
pm_runtime_resume_and_get() when streaming starts and drops it when
streaming stops. tw9900_remove() only calls pm_runtime_disable(), which
does not run the runtime suspend callback, so a device that is still
runtime active when the driver is unbound can keep its regulator enabled
and its reset line released.

After disabling runtime PM, call tw9900_runtime_suspend() if the device
is not runtime suspended, and set the runtime PM status to suspended.
This has to happen before the mutex is destroyed, as the callback takes
it.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes: 918b14a26b12 ("media: i2c: Introduce a driver for the Techwell TW9900 decoder")
Signed-off-by: Cong Nguyen <congnt264@xxxxxxxxx>
---
drivers/media/i2c/tw9900.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c
index 51db5d5ddbde..1baf55ea48ef 100644
--- a/drivers/media/i2c/tw9900.c
+++ b/drivers/media/i2c/tw9900.c
@@ -744,6 +744,10 @@ static void tw9900_remove(struct i2c_client *client)
v4l2_ctrl_handler_free(sd->ctrl_handler);

pm_runtime_disable(&client->dev);
+ if (!pm_runtime_status_suspended(&client->dev)) {
+ tw9900_runtime_suspend(&client->dev);
+ pm_runtime_set_suspended(&client->dev);
+ }

mutex_destroy(&tw9900->mutex);
}
--
2.25.1