[PATCH v7 02/12] media: tw9900: release the device when stopping the stream fails

From: Matthew Laux

Date: Fri Nov 20 2026 - 22:56:01 EST


If writing the register to stop streaming fails, the error path dropped
the runtime PM reference but left tw9900->streaming set. Then, s_stream(0)
again would drop the reference again and unbalance the usage count. At
that point any s_stream() is ignored because the driver thinks it's
streaming. Always clear the streaming state and drop the reference, and
only report the error.

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 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c
index e07924faa84b..e9d384039b50 100644
--- a/drivers/media/i2c/tw9900.c
+++ b/drivers/media/i2c/tw9900.c
@@ -303,14 +303,14 @@ static int tw9900_s_stream(struct v4l2_subdev *sd, int on)

ret = tw9900_write_reg(client, TW9900_REG_OUT_FMT_CTL,
TW9900_REG_OUT_FMT_CTL_STANDBY);
- if (ret)
- goto err_unlock;

tw9900->streaming = on;

mutex_unlock(&tw9900->mutex);

pm_runtime_put(&client->dev);
+
+ return ret;
}

return 0;
--
2.47.3