Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796045290; b=5YKa+7JRM7lny9/yTGQ7VuzQbYLTpGMfkXgzhsildOeYMFDHBfS+XNmGuKnqyydbYpB0 oY0v7K5baJR3ceL/inHogiXHvGFmyxi/wXbH9rVsks8XT95SajIY/EYukYekJqWpcrmKn po7fZhb3cfehQsmQTZIzYXrpQa7nKVdpj9BAjBtzbXMQn5zzcPWSO8zc5PzLRaH6bVxj3 zOFJETrWMaFePzj3cpZJM/T1edm4jX3zF/vXhmlmKkZeb4al4sBxfvuLqdk8rvrwS3Bg+ tjft221+/1DkaegYJQtxd1FRxCEWvgLwyJ4OfuHrUACFdr7H2n8J/++U+f4DAv4Z17g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796045290; 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=O+C70FFLakn/k5KD4ktHMRNBgKK9c+L7dIsXFX+8/GAXzbMatIWQrY80LH6iJ1WbhlhL A4imJMI6YC6Xn8hXyymLHfcxuFbdOrxcR2vpYAyVTHtMGQFAn9CO13LWWyyY9fukZDiqd n5QEl4MQyl0bFxvOSfNO3MS07wxHV3n9uMs8pfR+M0/X4eklHae3IilRaMd1X12tL7vQz LhT94Dh0EwIRUkcf2W3Oa70RSTeQwBpOLIxOTQJpNWn4wRGarX1p0Gk/88EmSwt1toxey QYwEMs9k09AwHJYqMgHORF05Kn4vW9oH7Gok36hs4KAOB1vFETOawEY+FacWGwkwrzQ== 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.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 05437606A32A for ; Mon, 30 Nov 2026 13:28:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 05437606A32A 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-f172.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso3509371eec.0 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=ncLZUKZgnS2pHgeElgYg7B2925ScrE3NV5BNNwpLonM+kUKqvdmVJ0quj1BAe1TwTy 3HDS0yARR9MrQr3sBHM2AcwD9n0pmD0gaaRIA4LAVtpMkH/ZSvuQHDgsoW++c02AA0NC vQ5BNcy09E+n9+6ZuXRITQvSu7zIYKckWlvYxO5r5Fb2qxq/PQYKYLqcnN2mIHhSntf4 QUMvkZdtNd52E4AcJ5HINfRL5ft8WF86Z9gK8e64PgIHjq7fCGDhdU/QIdjRLLH7hgCM OEXHKB9O+zmlzU+lZZBVgSgSegUR2g2fWB5E0ny6neCcHXVYswthRQsEWtBFrgAw9ned 5bjQ== X-Forwarded-Encrypted: i=1; AL+hErFhdSQi5d7C9xLDjU6V7g9qAtwJ0i/cNHncVPbyBYUMQQoyJAowgNT9PIIO/jhagEAcMuaarEM/E7cIEw==@vger.kernel.org X-Gm-Message-State: APuU4Z9ObVOJn3/c3uBu0N4UAM5JkjYcsdRkfwJsOLbGsehDun7BR4KZ i46aMgbdWty4pYW4plV2ro6jP+S9ZH9buUSOd1DjB5LNvcpkH9DbK2ts X-Gm-Gg: AZFdTZcmNgObOmFMZ+Ploq6OdGBDrs8nrnJ3Msr8hPH2ZibNSvGwehK5eIFjggd+FH/ vK8/iuY68noIeQpU4fNMgsrdV2npaNCsA6HGX24oe031+prTaREs13rDoA2485q/fgwDdtbQ7jx X6r1+KIqxJw2/wuMOWcPMDzzzXkTlwEYklLwjKxwUYKz953poA5qn9m7xBXClprLCdJrdouhoXd IHI1yVPSsUSz/LL3K7eW/P/b9qANtCAj2jaYxXavhbzdJ07HxyDajaQ41BXP5qhjAxMZV1A5mLR 1aH9zGflJcyIrMggsbHhkEmhydZ2XjVd7Iq+5PReRFsLcA+V1hNNfv7WwiFwhMnWrlhcKxyvfbn cPpjZEe2aYTt7C8SWOuYEkRDPr8paxZSjoYHR2mzu2gDDHOr1/5J6XJEapofe9nPo47r+rrOVBi O1QLjnt5Qzaa0YqWOI5d6H2yt7wkFrrOnv603dlFd0qqaGKxa7Zw2379eVd0VM98hdIjUlXvzJ/ XuNn83S/30sR9kz7021W5LkWfVDsu0TYXQGMAgbPeFLMjhS3a+wIEsiYM+jvS5hgFdcKXkKYg0a kR/utH/3B7thP/k7DanVIUDZ82b+GNnOOxEX3rhd6UvzWwhOggLJuZ3Kx+xPH3q2nbzPbIY8KqL 7lBLYy+dy0HOhOa++V7x09f7Y6vBi405ZVdkyBbc/zEt9OGI= 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-media@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