From: Yaohan Li <shunsheng1218@gmail.com>
To: Hans Verkuil <hverkuil@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] media: tc358743: free the interrupt before tearing down the state
Date: Mon, 30 Nov 2026 21:28:03 +0800 [thread overview]
Message-ID: <20261130132803.2078240-1-shunsheng1218@gmail.com> (raw)
tc358743_probe() registers the threaded interrupt handler with
devm_request_threaded_irq(), so the handler stays active during the
whole tc358743_remove() call. The handler reads registers and updates
V4L2 controls, but remove() destroys the control handler, the confctl
mutex and the CEC adapter before the devres cleanup frees the
interrupt, and the probe error paths do the same.
Request the interrupt with request_threaded_irq() and free it at the
top of remove(), which also waits for a running handler, before any of
the objects it uses are released. Do the same on the probe error
paths that run after the request, including before deleting the CEC
adapter if cec_register_adapter() fails.
Fixes: d747b806abf4 ("[media] tc358743: add direct interrupt handling")
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Based on v7.4-rc5 (fe6ff8d5d675).
Tested in QEMU x86_64 (KASAN + PROVE_LOCKING) using a virtual I2C adapter
emulating the tc358743 register file and a virtual IRQ controller (no
physical tc358743 hardware). Holding the threaded IRQ handler inside its
first register read during unbind hits a KASAN slab-use-after-free in
tc358743_s_ctrl_detect_tx_5v() on 4/4 unpatched runs; with this patch,
4/4 runs hit the same stall and unbind cleanly with 0 KASAN reports.
Build-tested on x86_64 and arm64 with W=1 (0 warnings). Not tested on
physical hardware.
AI assistance: Claude (Anthropic) helped with the analysis, the QEMU test
harness, and drafting the patch and changelog. I reviewed the root cause,
teardown order, test results, and the final patch.
drivers/media/i2c/tc358743.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index 8590e024c859..2987b3b13940 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -2274,11 +2274,10 @@ static int tc358743_probe(struct i2c_client *client)
tc358743_init_interrupts(sd);
if (state->i2c_client->irq) {
- err = devm_request_threaded_irq(&client->dev,
- state->i2c_client->irq,
- NULL, tc358743_irq_handler,
- IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
- "tc358743", state);
+ err = request_threaded_irq(state->i2c_client->irq, NULL,
+ tc358743_irq_handler,
+ IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+ "tc358743", state);
if (err)
goto err_work_queues;
} else {
@@ -2293,6 +2292,8 @@ static int tc358743_probe(struct i2c_client *client)
err = cec_register_adapter(state->cec_adap, &client->dev);
if (err < 0) {
pr_err("%s: failed to register the cec device\n", __func__);
+ if (state->i2c_client->irq)
+ free_irq(state->i2c_client->irq, state);
cec_delete_adapter(state->cec_adap);
state->cec_adap = NULL;
goto err_work_queues;
@@ -2303,11 +2304,11 @@ static int tc358743_probe(struct i2c_client *client)
err = v4l2_ctrl_handler_setup(sd->ctrl_handler);
if (err)
- goto err_work_queues;
+ goto err_free_irq;
err = v4l2_async_register_subdev(sd);
if (err < 0)
- goto err_work_queues;
+ goto err_free_irq;
i2c_wr8(sd, TYP_ACP_SET, packet_type);
i2c_wr8(sd, PK_AUTO_CLR, 0xff);
@@ -2324,6 +2325,9 @@ static int tc358743_probe(struct i2c_client *client)
return 0;
+err_free_irq:
+ if (state->i2c_client->irq)
+ free_irq(state->i2c_client->irq, state);
err_work_queues:
cec_unregister_adapter(state->cec_adap);
if (!state->i2c_client->irq) {
@@ -2343,7 +2347,9 @@ static void tc358743_remove(struct i2c_client *client)
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct tc358743_state *state = to_state(sd);
- if (!state->i2c_client->irq) {
+ if (state->i2c_client->irq) {
+ free_irq(state->i2c_client->irq, state);
+ } else {
timer_delete_sync(&state->timer);
flush_work(&state->work_i2c_poll);
}
--
2.34.1
reply other threads:[~2026-11-30 13:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261130132803.2078240-1-shunsheng1218@gmail.com \
--to=shunsheng1218@gmail.com \
--cc=hverkuil@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=p.zabel@pengutronix.de \
/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®