From nobody Thu Apr 2 15:05:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB51AECAAD8 for ; Thu, 22 Sep 2022 19:45:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbiIVTpJ (ORCPT ); Thu, 22 Sep 2022 15:45:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232146AbiIVTpF (ORCPT ); Thu, 22 Sep 2022 15:45:05 -0400 Received: from smtp.smtpout.orange.fr (smtp02.smtpout.orange.fr [80.12.242.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 085253334E for ; Thu, 22 Sep 2022 12:45:04 -0700 (PDT) Received: from pop-os.home ([90.11.190.129]) by smtp.orange.fr with ESMTPA id bS84oQyft94embS84oAvYz; Thu, 22 Sep 2022 21:45:02 +0200 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 22 Sep 2022 21:45:02 +0200 X-ME-IP: 90.11.190.129 From: Christophe JAILLET To: Support Opensource , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Adam Thomson Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , Dan Carpenter , alsa-devel@alsa-project.org Subject: [PATCH] ASoC: da7219: Fix an error handling path in da7219_register_dai_clks() Date: Thu, 22 Sep 2022 21:44:57 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If clk_hw_register() fails, the corresponding clk should not be unregistered. To handle errors from loops, clean up partial iterations before doing the goto. So add a clk_hw_unregister(). Then use a while (--i >=3D 0) loop in the unwind section. Fixes: 78013a1cf297 ("ASoC: da7219: Fix clock handling around codec level p= robe") Reported-by: Dan Carpenter Signed-off-by: Christophe JAILLET Reviewed-by: Dan Carpenter --- See https://lore.kernel.org/all/4fdde55198294a07f04933f7cef937fcb654c901.16= 24425670.git.christophe.jaillet@wanadoo.fr/ for an incomplete patch sent last year and Dan's comment on it. --- sound/soc/codecs/da7219.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c index 50ecf30e6136..4746c8700451 100644 --- a/sound/soc/codecs/da7219.c +++ b/sound/soc/codecs/da7219.c @@ -2196,6 +2196,7 @@ static int da7219_register_dai_clks(struct snd_soc_co= mponent *component) dai_clk_lookup =3D clkdev_hw_create(dai_clk_hw, init.name, "%s", dev_name(dev)); if (!dai_clk_lookup) { + clk_hw_unregister(dai_clk_hw); ret =3D -ENOMEM; goto err; } else { @@ -2217,12 +2218,12 @@ static int da7219_register_dai_clks(struct snd_soc_= component *component) return 0; =20 err: - do { + while (--i >=3D 0) { if (da7219->dai_clks_lookup[i]) clkdev_drop(da7219->dai_clks_lookup[i]); =20 clk_hw_unregister(&da7219->dai_clks_hw[i]); - } while (i-- > 0); + } =20 if (np) kfree(da7219->clk_hw_data); --=20 2.34.1