From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384897; b=gfLbk+xyOnasRiSa820i17Mvnp/AaSf5y8N6sz/YfCgmlA2VEyQNcFLvExh9U5js8aIJ Y0GBjQjd0rnH9B8gzajiytvPkfuDZQjklHFTEawUbWSflJwpqcq71t5aejNd0r8M2p/Y+ hjWczYqA4cd/MiKRdWX9+hc9ucQdjOJeE51Nf8/+wiLEG/j7aTaQ2TyQNekdyJlj7h0Tv FN3bSRgcao8rlntCe7YU4Dl2H10ifQ045KzsR0xc7gGOtiKNQ6XWjeOLmMiiX13Ww9NGx Bp5s5S41GZio3vdoOR09U8tK0afDqli21X4ti+X/l0lvKgPMnPSzz7eqh4/Mp4yAEiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384897; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=y26NQ4UIDRZHQfYmpoJvJDC5wVsGQnBAOmIzWv5zWcg=; b=Apy5rXOGd0GBuZXsUJBp4VD5KrV45rqOgc6ZIByzvf5r7GBeaWj/yU2T0I4W/SQK/Yoc 8rSrmHJys9KvcowNfL2RGX0CcJkGjcrBOJZhfIEOhF3rINYNvWvj29thXt6UhRjg5nWsq xoW6Ia6Z+ZhtgS/vukkeumL8SZM3P9cudV5zZP2jK7P3Aqqpj0VzkU7HCq2a0gPQ03H1u ZXLLyXrjXD0+pMXsG9JakeeVAqbPEesSK/5xdnTtNizGkZpsH25bG9GQ8Mq1kSDmgzLVV q7TL6QuUhsdMWDzAlCrULtoU9xY7omruAt8T7Pt1ez+XenMr2de0aMJ8n9OjzrhAm4g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xHmyMIIz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39D90606A322; Fri, 4 Dec 2026 11:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xHmyMIIz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12AE61F0092C; Fri, 4 Dec 2026 11:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384896; bh=y26NQ4UIDRZHQfYmpoJvJDC5wVsGQnBAOmIzWv5zWcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xHmyMIIzN0u+HtG9Gdi4Ljry38n4wutna+i3rpzk7g7Adn4t5c54Sjt9o1ZCnI3QW I9r0n6/KWe/5XfMkIHEIXUS4c+Gfm1I0oGp9vkrHKZVDPx5iGFIGanNEoX0L6yUwVi FlD4pNJyruR2kXrfqQzj2RAlz5uCkHjYr48SPqIQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, bui duc phuc , Cezary Rojewski , AngeloGioacchino Del Regno , Mark Brown , Sasha Levin Subject: [PATCH 6.6 0340/1167] ASoC: mediatek: mt8188: fix clk leak on error in audsys_clk_register Date: Fri, 4 Dec 2026 18:56:07 +0900 Message-ID: <20261204100710.849911991@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: bui duc phuc [ Upstream commit 6cddf6e56d2539fd13c0ee9dd817c4e06a967173 ] devm_add_action_or_reset() is called after the loop that registers gate clocks. If kzalloc() fails mid-loop, the function returns -ENOMEM before that call, so cleanup is never registered and all previously registered clocks leak permanently. Move devm_add_action_or_reset() before the loop so cleanup is always scheduled. The clock from the current (failing) iteration is not yet stored in afe_priv->lookup[i], so it still needs an explicit clk_unregister_gate() call. Fixes: fd67a7a1a22c ("ASoC: mediatek: mt8188: fix use-after-free in driver remove path") Signed-off-by: bui duc phuc Reviewed-by: Cezary Rojewski Reviewed-by: AngeloGioacchino Del Regno Link: https://patch.msgid.link/20260907120310.135693-8-phucduc.bui@gmail.com Signed-off-by: Mark Brown [ sashal: Kept the tree's kzalloc(sizeof(*cl), GFP_KERNEL) in place of upstream's kzalloc_obj(*cl), since that helper doesn't exist here. ] Signed-off-by: Sasha Levin --- sound/soc/mediatek/mt8188/mt8188-audsys-clk.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c b/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c index c796ad8b62eea..fd73f9d9f41a1 100644 --- a/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c +++ b/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c @@ -166,7 +166,7 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe) struct mt8188_afe_private *afe_priv = afe->platform_priv; struct clk *clk; struct clk_lookup *cl; - int i; + int i, ret; afe_priv->lookup = devm_kcalloc(afe->dev, CLK_AUD_NR_CLK, sizeof(*afe_priv->lookup), @@ -175,6 +175,10 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe) if (!afe_priv->lookup) return -ENOMEM; + ret = devm_add_action_or_reset(afe->dev, mt8188_audsys_clk_unregister, afe); + if (ret) + return ret; + for (i = 0; i < ARRAY_SIZE(aud_clks); i++) { const struct afe_gate *gate = &aud_clks[i]; @@ -190,8 +194,10 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe) /* add clk_lookup for devm_clk_get(SND_SOC_DAPM_CLOCK_SUPPLY) */ cl = kzalloc(sizeof(*cl), GFP_KERNEL); - if (!cl) + if (!cl) { + clk_unregister_gate(clk); return -ENOMEM; + } cl->clk = clk; cl->con_id = gate->name; @@ -202,5 +208,5 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe) afe_priv->lookup[i] = cl; } - return devm_add_action_or_reset(afe->dev, mt8188_audsys_clk_unregister, afe); + return 0; } -- 2.53.0