Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp14195rwb; Thu, 22 Sep 2022 13:39:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5sQpxXVO9FxgIs4Pa1mcquOqVfNEFDZkP4GGl27IbhQehw32gbkNNzN+HUOHBaAU37AL+j X-Received: by 2002:a63:2341:0:b0:434:d9b8:cfdf with SMTP id u1-20020a632341000000b00434d9b8cfdfmr4500876pgm.446.1663879141706; Thu, 22 Sep 2022 13:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663879141; cv=none; d=google.com; s=arc-20160816; b=pgKrE7nA+8Nnn/BOTwy1Npin6QHX9L8Zrq8y/ppJ71cWH44MmEocaAue34J1kqobUY dIK6Np9bDAb8nSfFe3qI1zBV7it8bO+48reqs7Mls0zMjkAi4dmE2q3r5G09idxIBmzL XtSauKIsD6mWC7Lksdx137sFaPcmguD3r/vZlm/YGy/YXuFjzvWPf002UydLmFTTN5/Z V9afL56+9tD3XyOteW5w09Uul+IWuHFhsocngbdk2g5WTAdR0GmsGnZw/hp5HcZe+rj2 IX2aTfggRbkVZR0ilzgwpWzBcVm0/mW/edyQSj8a2ZQlZPsPBjUql7WHtCWPJu2xR8v0 LpSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=wIA/5HRSFtlXVTw5FX772xCWIuOu6yv/JnqxdgbxTn4=; b=NpcoNHoEqFvAbODyZMrDFVLA0MyGrDrMGZdLmWVbY3c22//p00vi1fv/PaqBGkyPm6 mTXK2x5T57DNsvqphillq+pL1NUw9rhtowN9gfRZz9YLXTH1BREAKE/IP4cZLX4RNUup JpIDLK+hr3x7bkzaAfUGzPpQO7aW+Ey2ffD80B88rqh79l6dyoc2Qz3ngvBYzYpcKCTc Jyoz9BB1QuFCbxtdMCgkWJ2i4LgeEHzJ0gyVdjnEKfLW+ClXNYZ9z+lIRLjmc+p4BgZu R3fo9/a3F+2sTSnwvV2YItL65r47rcgzPqXrMDnW76UTqcdG2ix7ZE4gLn9dw4T/TCaF 2Icw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a17090311c400b00178af7f1832si1078759plh.216.2022.09.22.13.38.50; Thu, 22 Sep 2022 13:39:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232360AbiIVTpH (ORCPT + 99 others); Thu, 22 Sep 2022 15:45:07 -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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >= 0) loop in the unwind section. Fixes: 78013a1cf297 ("ASoC: da7219: Fix clock handling around codec level probe") Reported-by: Dan Carpenter Signed-off-by: Christophe JAILLET --- See https://lore.kernel.org/all/4fdde55198294a07f04933f7cef937fcb654c901.1624425670.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_component *component) dai_clk_lookup = clkdev_hw_create(dai_clk_hw, init.name, "%s", dev_name(dev)); if (!dai_clk_lookup) { + clk_hw_unregister(dai_clk_hw); ret = -ENOMEM; goto err; } else { @@ -2217,12 +2218,12 @@ static int da7219_register_dai_clks(struct snd_soc_component *component) return 0; err: - do { + while (--i >= 0) { if (da7219->dai_clks_lookup[i]) clkdev_drop(da7219->dai_clks_lookup[i]); clk_hw_unregister(&da7219->dai_clks_hw[i]); - } while (i-- > 0); + } if (np) kfree(da7219->clk_hw_data); -- 2.34.1