From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796045289; b=n583wcoY1wPTqiYx/aQ7pL7+MWghe37QnZGOSodzFdPul3Ru0IRjNPwZLVMtywBIMer3 W8N8lqQvUD+F28EK847zYTA5s/JvUjqdX8yYcvK/XLEGHssj83MHfbCJX99AqXSPPqmbI tyneI/fWeIY4bSmwuCTFqXXjDnl4mx+LJM4cRNmwhEiRFp0Qv9NjOiIqaisa6wuL83yP7 /abSs4uNFXz3uHIW4VnwICDxFQG+5QD0xZ10sIfejhHR1uF3omp1oSERbsvmGthQrhRbi UL3eG/3pQty02nr6RTizkJqn8cLZfp7P9FQXVOnvxI4EhfnLtSbyq6/piKbz1FqTiHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796045289; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=HS6BtCf447Jm37HSdxZsni6OJ3/KVqJIXjTGuN/s/G8=; b=ieYHmkmhcDH8wO+b1kKOKzKQ3ZmzmK1ZKoDTnojm15CXGvQ6MIoNiL0Xooaams8Bg6Uz adPugQloOSw47iCw0YTUnANJc5KASqMgk9vXtiJI//UflzWqO70IJlcrOl51ejKWKjg47 99iFUcqjjsNvH85bFcFCfC4jz2g+syFAo/w5NiY83JT8zYJj/E6ffC31+nz3so/OlsXB5 Iop5LqkvSMfdOZ3hGeFskZThDva1qQoYRS+vncKFz3EZ4l//fPRpg+HdeKc4k/7VZjm+3 icJ5vlfV5a8GxYCApLZl+4O+SlUKX359bXZllX5Kq/35UdWC00eZYv3c/KOb5c7bidQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="Z/jmNxJX"; arc=none smtp.remote-ip=74.125.82.181 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B75E606A327 for ; Mon, 30 Nov 2026 13:28:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B75E606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Z/jmNxJX Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-386bd881d39so3250083eec.1 for ; Mon, 30 Nov 2026 05:28:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796045288; x=1796650088; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=HS6BtCf447Jm37HSdxZsni6OJ3/KVqJIXjTGuN/s/G8=; b=Z/jmNxJX1smgO2czxr1Z2S87yPKcgDptT0F1sR8d2+GQ6PLC0a280f0L5kC1d8k5cD I7/FtR4Xqr8BUNNW1bnHbsQbSoeSH17s8y/MmCf48czj4jWhbDVV4m7QaLX0dXsHYEUQ jfSXEsQOT/huTfkZE0mWUNEv68B8EuOjsD7rtRYV4Cr2VbB6Cxq9TZby3NeoVSywQSs8 BE+KSD7JjVt8Ga0rngP/x+MnsT0NC/ljgwRuJhfp6vyKNar05e79yfusGh0bTz2UQc+k gTUpjwyGarFuUzm39wiU/QY1eI/tKezndYCVxM+Dp8m/hJvjZyX2Z+6qGL9CFglpNth/ YEwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796045288; x=1796650088; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HS6BtCf447Jm37HSdxZsni6OJ3/KVqJIXjTGuN/s/G8=; b=fr6JN7BAELuwlRo5bhqH3FNKJtVs+MVc/d6przOAhTe2vA1q2nz5VLmBHHhJtZ6aZM x9kKp/XFfg2IVgdmlTmKoewxd2DvT2rESZLFxTO5QVI9ezlpUrzIUiwxER5k/1juouvs 049NrDNBr8NmEtkpL3lOXPez1eZwVH9gUXRbBPIZ+Sm10vLJIQOzCHFP2I+hu4mtOusz 5oAzBCfqw1n7DO9LBRwLklAWYqxhiRaumf6qVCEaJb//XaeUwMikGtzd3Qk8uwDntBoh denvt855b7QLX+bHYau/8wwHzWu+/qKNDlNAvfs0ROKFZacltM3Bc8IysIsM5jE/FlAu Bjpg== X-Forwarded-Encrypted: i=1; AL+hErEodG2+B0bMlRqT7rCzBtaiKPzmHXbrZ9h7cRFX3fxb/RujKgJrswF5+hfVQqXZAbtUbV+mkyBJ0W7nzc4=@vger.kernel.org X-Gm-Message-State: APuU4Z/qdMOX23nIno/O9wvxmFJqXBjaPozji7T6IBa69kpUzmzglF0X uUDCZy9eX9Kyva6NGizM6agnY5enu/W6GS8M2Wi9Zer+JqlLktnu/uXJ65c6YUZhF+5xLw== X-Gm-Gg: AZFdTZcqrVJHXsRNIruAAgAqAx7PP2ujaiAgd7+tYEospho0hfT80AFw7Y/RpvkvuLD FKT8AsL6Pd4BBfVlv6A+LL/vkNnmHeW21mUvGGQoDka7lCjptXLDsT0yIqwa6fDkyYvOptBESLM 4cpYWATU+zqPKRxNqDNpbIu93MDpD7xB/THO2eTvrdezgkwu0exteHG3fZHLDAmsQbmYoFgqvK9 iieHRsmzgVDpLwNmBwnwKso4UJJZxWZPb/w0FrXEnZmGFCUa0h1nnL3A0kjfRphuNKLUK3MF81m 00cy45ApE0Ta8ZuVawIMgaE6L6R4uzdmniFvnqWrpqVfD1+uymwEy5/TxQ76Ib/WXWLg/KGsHI8 fB/2vWBJK6ijqIsjVKKsgZ+IA9iQyuWmN7mEgMiu5DksC/KJVHWMx3srKNnB0hKE9tDDApqYbbe lXNwKPHWw/vHY+5+j471w9w0AodAnphtEJFDtnkxJpB9WzYUsb4ShUN/ouwVcC6emCWgvyI3wmj nuQYVEbS0/5X4alrW4XNxdN0HiQfKBtBFcNQvaW2Avbi+Donio6QQC1fXA6FT5mRu3i/i74OJUF i2ojXcyVM8gJw7i0RKfMHyDYFB1/a7k2ahCxtF94unHn0sg74zFPY5B8JnSzaqvu4Qe13Eub8mV 6dZcfsm7jR9juLq8FdeWcs8EkEty7yLd754WspbK8iLLu9sg= X-Received: by 2002:a05:7300:4721:b0:386:da66:671f with SMTP id 5a478bee46e88-386da66762cmr13912923eec.28.1796045287904; Mon, 30 Nov 2026 05:28:07 -0800 (PST) Received: from lwq-server.tail118c18.ts.net ([74.176.208.23]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385677c371esm99945981eec.23.2026.11.30.05.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 05:28:07 -0800 (PST) From: Yaohan Li To: Hans Verkuil , Mauro Carvalho Chehab Cc: Philipp Zabel , 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 Message-Id: <20261130132803.2078240-1-shunsheng1218@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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