From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796045295; b=1EQeCG1hu6INkvRLVd0IRYcO+cRddyoN+3Wny0PJDcDHPjXrADAYl/SxPOxv/E65djDX q+k//UrO5wqvD4VigSqrR8cR10iXPnYaPBDWPSdtXUN0w56HHfT+oT93LIAC4pnbTCM3K xGLOxcbwuN73aVlSxbT3lpx+tWJ4ORdGTTCHL0tqKyU9UQApZZ1ux5fawSuKJtanGBmi2 9Nbr+4dYeAcsye4EbIfwD+M5Wy4M7s6sg/mFoqDdTsZX1rnMmecHeryi5qWpJTTpYOWKb XNOuPjJPaP1eCgwWXpN219MYjz7jAuvWIWGwfpqDzvy9mblBWr8rSIfoyyw6GRKqQSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796045295; 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=fK0ytGQ7SP4Lui7ldzIPYdpMYayAiIzwIH/ogQU7EQ0=; b=TcxvG/j9wILp6xp8cyeGy2YEDJFc1hD7H8f353lHkKWsOHwhwikPE5SVDOjH+fo9NYrI VO/JBoW3ga//c+h0UcjC4YeyVJgFj1E9fGPqe2E1WYdaXuwRrwLosdrBm0hNCebxqstwH MKqYTr02ftpn7ZpN943Ixc2Dp1xEGe14vonCWOt0qup1FkbhfBHC4GUXFALgLK14dEAND OegpfJXAyScL44pFLJKnjwn++WDOl5UukoIzC91zEoMiGFOck7XEvFaecgLFOTWeNDzaI itn8/5lVZY6wbYeLOKjIFmXOkjSQqAO0a1gWfD/OwpGkaRKYylmEmQw3q1XUFHOLd2A== 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=fsnoLQSY; arc=none smtp.remote-ip=74.125.82.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (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 D90DF606A32E for ; Mon, 30 Nov 2026 13:28:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D90DF606A32E 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=fsnoLQSY Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1b546061d58so3994598c88.1 for ; Mon, 30 Nov 2026 05:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796045294; x=1796650094; 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=fK0ytGQ7SP4Lui7ldzIPYdpMYayAiIzwIH/ogQU7EQ0=; b=fsnoLQSYz+Nyac83ET+rQX+13G5JNPIKiE6W7O+NkPYZuwJ2XteY6GydBIa2HWandP J7CIL/AhaQSKTf82QPQGYp0u1CGQ+xtPBtflCNyDQn/lmSxjVwJylWmemybj+FJHM5j5 oCpc7nnyamX5XVMi4eAWzA9lqcC+RDTFvVnE6jUBCbyO8BbrV8IhzgCqZsdzJMAcBVDA 1HL6858MC7GjGUXJsJnuzMYI7gM/CiFZgFjek9L7aL8QCFBQFnV2ws1BhU0Uc7it2qmE A5P1sgcPSk9iRDVBiutIAi1H09yHOrcmCUMR/UFqhSud1nBru1m/oQ4X769gS/IxHr2Y dgIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796045294; x=1796650094; 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=fK0ytGQ7SP4Lui7ldzIPYdpMYayAiIzwIH/ogQU7EQ0=; b=J+0Ha9myyGVJOJqM9eW9Ij1t3SbH0yZhvPtS63O9Gp0ZLY/mdetEhadSE6Q74AG8L+ XGyVXBcudjHmL8Ul76emwMaAc+utfzcfrLAJ8AmB445D7rUBlcC+UXaAGnp9rc56wMA7 3zuxxut4P5/y/tGzh5eV4+QOivCxcx+kJK/5PYAbNS8Kazjw3NQAZKsLkRHp13V6OnbI XeOzEN86h7CJqg6Ss7Lpk8NxcZiuH3tetjdaQhYw5uBYcnnrJM31ZgZnm+FckuRYE9Nc pRe/I/OI7ZlnDr+YBd1A6G0fUKnf+PSu+gDk8ybdvQpG1hraROvvjwjPE8m9rOrQ+BBc hsUQ== X-Forwarded-Encrypted: i=1; AL+hErEeBDtGtqCBVfGIHuiFuYtjoVUwrJbCX9NvqjsdK2IQTnf5WyLEKW1oSK88WzZpyy/3bEZ9Ev/FvFXkMNU=@vger.kernel.org X-Gm-Message-State: APuU4Z/fxbqn/FgdqLfFKEfWlCO3jkCnPAo3thEITtma5nstWcmRqjdg LZfAYlEA21iRMMDxU0j8rNkV8Hevt7nKQfD2yaQuaQdYShphX61/Xjnj X-Gm-Gg: AZFdTZeubGBF8RPtCOmbbokXsbrtJxd4oBocixrI0gz+ar+oAS5/nyHjLKkp0cwXT+A ilpw3+dwfLbogJSpI6cm8VeljAFJ0HYBluGFZfTCIRBxF9oYbEPFRLWRpzz8stNfElj0hmPpZnG F6joil2w6LBD7U0pIQI9JO8Gw+t6fR3nZFcrqfFUydIO4RqWNpBBChLUsz1gtywxj0k7/eX8qOg YMBeaDOa/phVAAfxecA+spICmAtWUvG/9cAjplcIxhMrfNasMuDmwxzmSyADz2tinxytYyn4GjV aB44alo5AR2puHAggIwQIHcnToOVJL5vCVmiOLrW+ooUZTJsVZ8Qbola0mgnjk2KD2+1yZhg7Xy 6cWqEVtJ8fgq/nsgzNWwSq2uQ8Y3m0/AzB80UEbbDFVs5gF8YD1Amp9boEXIcKqcBq790XfST/D sctfl7J0WZJSsHXhuN+YJmg5skU6inZxWRaSlSF/F4lltOfZEkHNppngoreVANBazG9/Bqwlh0B w4YqpW95DyfcoU0I9HQS1M3AhOjxtIEcaAoWU0I6pfzWMZcK6QKF6/JLVYv4n9TRGUeUGnoXEk3 IT3SFujafbOof+ot5nLuSK3rDJzBMeYDdAxYYy95qcY+51bxDr1op33V6J6ShKp85FIyRlzeMSf Uupmy0hsFw4Ok1H9wNTXStSmjxVqCbL9rweR94agVHeoHHh8/ X-Received: by 2002:a05:7022:7f12:b0:1b5:4dff:8b67 with SMTP id a92af1059eb24-1b5568eeba1mr32181334c88.29.1796045293755; Mon, 30 Nov 2026 05:28:13 -0800 (PST) Received: from lwq-server.tail118c18.ts.net ([74.176.208.23]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556847fdasm87009468c88.13.2026.11.30.05.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 05:28:13 -0800 (PST) From: Yaohan Li To: Oder Chiou , Liam Girdwood , Mark Brown Cc: Jaroslav Kysela , Takashi Iwai , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: rt5645: stop timer and delayed works on probe error Date: Mon, 30 Nov 2026 21:28:08 +0800 Message-Id: <20261130132808.2078478-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 rt5645_i2c_probe() requests the threaded IRQ before calling devm_snd_soc_register_component(). If component registration fails, err_irq calls free_irq() without cancelling rt5645->jack_detect_work, which the IRQ handler may already have queued to run 250 ms later after devres frees rt5645. Match rt5645_i2c_remove() in err_irq: shut down btn_check_timer and cancel jack_detect_work and rcclock_work after free_irq() so no timer or delayed work remains active when probe returns an error. Fixes: cd6e82b814ca ("ASoC: rt5645: Add the workqueue of the jack detect function for the debouncing") Signed-off-by: Yaohan Li --- Based on v7.4-rc5 (fe6ff8d5d675). Tested in QEMU x86_64 (KASAN + PROVE_LOCKING) using a virtual I2C adapter and a virtual IRQ controller (no physical rt5645 hardware). Failing devm_snd_soc_register_component() via failslab while an IRQ fires queues jack_detect_work, which runs after devres frees rt5645: unpatched hits a KASAN slab-use-after-free in __run_timer_base on the first of 10/10 fault-injected iterations (single-shot KASAN); with this patch, 10/10 iterations complete and unload cleanly with 0 KASAN reports. Note that only jack_detect_work was dynamically reproduced on this probe failure path; btn_check_timer and rcclock_work are not armed while rt5645->component is NULL and are torn down here to stay symmetric with rt5645_i2c_remove() and prevent timer/work rearming across teardown. 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. sound/soc/codecs/rt5645.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index e14b66d3118d..dbbd12e637e7 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -4282,6 +4282,9 @@ static int rt5645_i2c_probe(struct i2c_client *i2c) err_irq: if (rt5645->i2c->irq) free_irq(rt5645->i2c->irq, rt5645); + timer_shutdown_sync(&rt5645->btn_check_timer); + cancel_delayed_work_sync(&rt5645->jack_detect_work); + cancel_delayed_work_sync(&rt5645->rcclock_work); err_enable: regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); return ret; -- 2.34.1