media: tc358743: free the interrupt before tearing down the state
Subsystems (2)
PATCH 1/1 media: tc358743: free the interrupt before tearing down the state
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.
---
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(-)
drivers/media/i2c/tc358743.c +14 -8
@@ -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); }
Signature · 1 line
2.34.1