mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Laux <matthew.laux@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@kernel.org>,
	Mehdi Djait <mehdi.djait@bootlin.com>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	Matthew Laux <matthew.laux@gmail.com>
Subject: [PATCH v7 06/12] media: tw9900: power off the device on remove if still active
Date: Fri, 20 Nov 2026 21:55:17 -0600	[thread overview]
Message-ID: <20261121035523.26764-7-matthew.laux@gmail.com> (raw)
In-Reply-To: <20261121035523.26764-1-matthew.laux@gmail.com>

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@gmail.com>
---
 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


  parent reply	other threads:[~2026-11-21  3:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  3:55 [PATCH v7 00/12] Add driver for StarTech USB3HDCAP capture device Matthew Laux
2026-11-21  3:55 ` [PATCH v7 01/12] media: tw9900: Disable regulator on runtime resume failure Matthew Laux
2026-11-21  3:55 ` [PATCH v7 02/12] media: tw9900: release the device when stopping the stream fails Matthew Laux
2026-11-21  3:55 ` [PATCH v7 03/12] media: tw9900: accept the TW9910 chip ID Matthew Laux
2026-11-21  3:55 ` [PATCH v7 04/12] media: tw9900: add saturation, hue and sharpness controls Matthew Laux
2026-11-21  3:55 ` [PATCH v7 05/12] media: tw9900: program all mode registers in the PAL table Matthew Laux
2026-11-21  3:55 ` Matthew Laux [this message]
2026-11-21  3:55 ` [PATCH v7 07/12] media: tw9900: power down analog blocks in runtime suspend Matthew Laux
2026-11-21  3:55 ` [PATCH v7 08/12] media: tw9900: use runtime PM autosuspend Matthew Laux
2026-11-21  3:55 ` [PATCH v7 09/12] media: tw9900: allow board-specific register tables via platform data Matthew Laux
2026-11-21  3:55 ` [PATCH v7 10/12] media: tw9900: add S-Video input and progressive source detection Matthew Laux
2026-11-21  3:55 ` [PATCH v7 11/12] media: Add subdevice driver for the Mstar MST3367 HDMI receiver Matthew Laux
2026-11-21  3:55 ` [PATCH v7 12/12] media: add driver for StarTech USB3HDCAP Matthew Laux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261121035523.26764-7-matthew.laux@gmail.com \
    --to=matthew.laux@gmail.com \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mehdi.djait@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®