mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: i2c: tw9900: disable vdd on resume failure
@ 2026-11-19  8:14 Wang Haoran
  0 siblings, 0 replies; only message in thread
From: Wang Haoran @ 2026-11-19  8:14 UTC (permalink / raw)
  To: mehdi.djait; +Cc: mchehab, linux-media, linux-kernel, wanghr2026

tw9900_runtime_resume() enables the vdd regulator but if the init register
writes fail the regulator is left enabled and the resume error sets
runtime_error, after which runtime_suspend() is never called again. The
only regulator_disable() lives in runtime_suspend(), so a single I2C error
in the first resume (which happens during probe's check_id) leaves the rail
enabled until reboot, even across unbind and probe retries.

Disable the regulator when the register write fails.

Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: 918b14a26b12 ("media: i2c: Introduce a driver for the Techwell TW9900 decoder")
---

diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c
index 51db5d5ddbde..b4fb566807a8 100644
--- a/drivers/media/i2c/tw9900.c
+++ b/drivers/media/i2c/tw9900.c
@@ -624,6 +624,8 @@ static int tw9900_runtime_resume(struct device *dev)
 
 	ret = tw9900_write_array(tw9900->client, tw9900_init_regs,
 				 ARRAY_SIZE(tw9900_init_regs));
+	if (ret)
+		regulator_disable(tw9900->regulator);
 
 	mutex_unlock(&tw9900->mutex);
 

---

PoC reproduction (7.4.0-rc2, arm64 QEMU virt, unmodified kernel):

Route 1 (i2c-stub, no DT injection needed):

    modprobe i2c-stub chip_addr=0x2c
    echo "tw9900 0x40" > /sys/bus/i2c/devices/i2c-0/new_device

The probe triggers the first runtime_resume during check_id and the init
register write fails on the unanswered address.

Result:

    i2c i2c-0: new_device: Instantiated device tw9900 at 0x40
    tw9900 0-0040: write reg error: -19
    WARNING: drivers/regulator/core.c:2678 at _regulator_put

The regulator-dummy use count rises by one on every failed probe (and on
every delete/new_device retry) and never drops, because runtime_suspend is
blocked by the runtime_error state.

Note: the PoC was generated with AI assistance and the vulnerability was
found by static analysis. Triggering the failed probe via sysfs requires
root, so this is not a security fix, but it prevents a potential resource
leak on a failed probe.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19  8:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  8:14 [PATCH] media: i2c: tw9900: disable vdd on resume failure Wang Haoran

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®