From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 247A7C49EA6 for ; Wed, 23 Jun 2021 21:13:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B87761374 for ; Wed, 23 Jun 2021 21:13:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229688AbhFWVQK (ORCPT ); Wed, 23 Jun 2021 17:16:10 -0400 Received: from smtp11.smtpout.orange.fr ([80.12.242.133]:45092 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbhFWVQJ (ORCPT ); Wed, 23 Jun 2021 17:16:09 -0400 Received: from [192.168.1.18] ([86.243.172.93]) by mwinf5d90 with ME id LlDn2500Q21Fzsu03lDnbG; Wed, 23 Jun 2021 23:13:49 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 23 Jun 2021 23:13:49 +0200 X-ME-IP: 86.243.172.93 Subject: Re: [PATCH] ASoC: da7219: Fix an out-of-bound read in an error handling path To: Dan Carpenter Cc: alsa-devel@alsa-project.org, support.opensource@diasemi.com, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, tiwai@suse.com, broonie@kernel.org, Adam.Thomson.Opensource@diasemi.com Newsgroups: gmane.linux.alsa.devel,gmane.linux.kernel,gmane.linux.kernel.janitors References: <4fdde55198294a07f04933f7cef937fcb654c901.1624425670.git.christophe.jaillet@wanadoo.fr> <20210623094655.GB2116@kadam> From: Christophe JAILLET Message-ID: <8e0d461a-c633-0162-b9e6-c2166bc013fe@wanadoo.fr> Date: Wed, 23 Jun 2021 23:13:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210623094655.GB2116@kadam> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 23/06/2021 à 11:46, Dan Carpenter a écrit : > On Wed, Jun 23, 2021 at 07:22:45AM +0200, Christophe JAILLET wrote: >> If 'of_clk_add_hw_provider()' fails, the previous 'for' loop will have >> run completely and 'i' is know to be 'DA7219_DAI_NUM_CLKS'. >> >> In such a case, there will be an out-of-bounds access when using >> 'da7219->dai_clks_lookup[i]' and '&da7219->dai_clks_hw[i]'. >> >> To avoid that, add a new label, 'err_free_all', which set the expected >> value of 'i' in such a case. >> >> Fixes: 78013a1cf297 ("ASoC: da7219: Fix clock handling around codec level probe") >> Signed-off-by: Christophe JAILLET >> --- >> sound/soc/codecs/da7219.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c >> index 13009d08b09a..1e8b491d1fd3 100644 >> --- a/sound/soc/codecs/da7219.c >> +++ b/sound/soc/codecs/da7219.c >> @@ -2204,12 +2204,14 @@ static int da7219_register_dai_clks(struct snd_soc_component *component) >> da7219->clk_hw_data); >> if (ret) { >> dev_err(dev, "Failed to register clock provider\n"); >> - goto err; >> + goto err_free_all; >> } >> } >> >> return 0; >> >> +err_free_all: >> + i = DA7219_DAI_NUM_CLKS - 1; >> err: >> do { >> if (da7219->dai_clks_lookup[i]) > > This do while statement is wrong and it leads to potentially calling > clk_hw_unregister() on clks that haven't been registered. Obviously right. Thanks for the review Dan. I'll send a v2 in the coming days. CJ > > I think that calling clk_hw_unregister() on unregistered clocks is > supposed to okay but I found a case where it leads to a WARN_ON() > (Nothing else harmful). It's in __clk_register() if the alloc_clk() > fails: > > hw->clk = alloc_clk(core, NULL, NULL); > if (IS_ERR(hw->clk)) { > ret = PTR_ERR(hw->clk); > goto fail_create_clk; // <- forgot to set hw->clk = NULL > } > > The better way to handle errors from loops is to clean up partial > iterations before doing the goto. So add a clk_hw_unregister() if the > dai_clk_lookup = clkdev_hw_create() assignment fails. Then use a > while (--i >= 0) loop in the unwind section: > > err_free_all: > i = DA7219_DAI_NUM_CLKS; > err: > while (--i >= 0) { > > regards, > dan carpenter > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E414C48BC2 for ; Wed, 23 Jun 2021 21:15:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1377461166 for ; Wed, 23 Jun 2021 21:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbhFWVRW (ORCPT ); Wed, 23 Jun 2021 17:17:22 -0400 Received: from ciao.gmane.io ([116.202.254.214]:48384 "EHLO ciao.gmane.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbhFWVRV (ORCPT ); Wed, 23 Jun 2021 17:17:21 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lwAD8-000591-Gc for linux-kernel@vger.kernel.org; Wed, 23 Jun 2021 23:15:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: linux-kernel@vger.kernel.org From: Christophe JAILLET Subject: Re: [PATCH] ASoC: da7219: Fix an out-of-bound read in an error handling path Date: Wed, 23 Jun 2021 23:13:46 +0200 Message-ID: <8e0d461a-c633-0162-b9e6-c2166bc013fe@wanadoo.fr> References: <4fdde55198294a07f04933f7cef937fcb654c901.1624425670.git.christophe.jaillet@wanadoo.fr> <20210623094655.GB2116@kadam> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 Cc: alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org In-Reply-To: <20210623094655.GB2116@kadam> Content-Language: en-US Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Message-ID: <20210623211346.P8Hw2JEEPVpsvZctNGkhC4RY_7-khApaZRWKz1AYryQ@z> Le 23/06/2021 à 11:46, Dan Carpenter a écrit : > On Wed, Jun 23, 2021 at 07:22:45AM +0200, Christophe JAILLET wrote: >> If 'of_clk_add_hw_provider()' fails, the previous 'for' loop will have >> run completely and 'i' is know to be 'DA7219_DAI_NUM_CLKS'. >> >> In such a case, there will be an out-of-bounds access when using >> 'da7219->dai_clks_lookup[i]' and '&da7219->dai_clks_hw[i]'. >> >> To avoid that, add a new label, 'err_free_all', which set the expected >> value of 'i' in such a case. >> >> Fixes: 78013a1cf297 ("ASoC: da7219: Fix clock handling around codec level probe") >> Signed-off-by: Christophe JAILLET >> --- >> sound/soc/codecs/da7219.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c >> index 13009d08b09a..1e8b491d1fd3 100644 >> --- a/sound/soc/codecs/da7219.c >> +++ b/sound/soc/codecs/da7219.c >> @@ -2204,12 +2204,14 @@ static int da7219_register_dai_clks(struct snd_soc_component *component) >> da7219->clk_hw_data); >> if (ret) { >> dev_err(dev, "Failed to register clock provider\n"); >> - goto err; >> + goto err_free_all; >> } >> } >> >> return 0; >> >> +err_free_all: >> + i = DA7219_DAI_NUM_CLKS - 1; >> err: >> do { >> if (da7219->dai_clks_lookup[i]) > > This do while statement is wrong and it leads to potentially calling > clk_hw_unregister() on clks that haven't been registered. Obviously right. Thanks for the review Dan. I'll send a v2 in the coming days. CJ > > I think that calling clk_hw_unregister() on unregistered clocks is > supposed to okay but I found a case where it leads to a WARN_ON() > (Nothing else harmful). It's in __clk_register() if the alloc_clk() > fails: > > hw->clk = alloc_clk(core, NULL, NULL); > if (IS_ERR(hw->clk)) { > ret = PTR_ERR(hw->clk); > goto fail_create_clk; // <- forgot to set hw->clk = NULL > } > > The better way to handle errors from loops is to clean up partial > iterations before doing the goto. So add a clk_hw_unregister() if the > dai_clk_lookup = clkdev_hw_create() assignment fails. Then use a > while (--i >= 0) loop in the unwind section: > > err_free_all: > i = DA7219_DAI_NUM_CLKS; > err: > while (--i >= 0) { > > regards, > dan carpenter > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C444C48BC2 for ; Wed, 23 Jun 2021 21:25:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C53460D07 for ; Wed, 23 Jun 2021 21:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbhFWV1X (ORCPT ); Wed, 23 Jun 2021 17:27:23 -0400 Received: from ciao.gmane.io ([116.202.254.214]:57266 "EHLO ciao.gmane.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbhFWV1X (ORCPT ); Wed, 23 Jun 2021 17:27:23 -0400 X-Greylist: delayed 301 seconds by postgrey-1.27 at vger.kernel.org; Wed, 23 Jun 2021 17:27:23 EDT Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lwAHy-00012l-IS for kernel-janitors@vger.kernel.org; Wed, 23 Jun 2021 23:20:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: kernel-janitors@vger.kernel.org From: Christophe JAILLET Subject: Re: [PATCH] ASoC: da7219: Fix an out-of-bound read in an error handling path Date: Wed, 23 Jun 2021 23:13:46 +0200 Message-ID: <8e0d461a-c633-0162-b9e6-c2166bc013fe@wanadoo.fr> References: <4fdde55198294a07f04933f7cef937fcb654c901.1624425670.git.christophe.jaillet@wanadoo.fr> <20210623094655.GB2116@kadam> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org In-Reply-To: <20210623094655.GB2116@kadam> Content-Language: en-US Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kernel-janitors@vger.kernel.org Message-ID: <20210623211346.SirTrdj6tJt0eOF_FBULbI3HN_TJhTaZNO20FfkH214@z> Le 23/06/2021 à 11:46, Dan Carpenter a écrit : > On Wed, Jun 23, 2021 at 07:22:45AM +0200, Christophe JAILLET wrote: >> If 'of_clk_add_hw_provider()' fails, the previous 'for' loop will have >> run completely and 'i' is know to be 'DA7219_DAI_NUM_CLKS'. >> >> In such a case, there will be an out-of-bounds access when using >> 'da7219->dai_clks_lookup[i]' and '&da7219->dai_clks_hw[i]'. >> >> To avoid that, add a new label, 'err_free_all', which set the expected >> value of 'i' in such a case. >> >> Fixes: 78013a1cf297 ("ASoC: da7219: Fix clock handling around codec level probe") >> Signed-off-by: Christophe JAILLET >> --- >> sound/soc/codecs/da7219.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c >> index 13009d08b09a..1e8b491d1fd3 100644 >> --- a/sound/soc/codecs/da7219.c >> +++ b/sound/soc/codecs/da7219.c >> @@ -2204,12 +2204,14 @@ static int da7219_register_dai_clks(struct snd_soc_component *component) >> da7219->clk_hw_data); >> if (ret) { >> dev_err(dev, "Failed to register clock provider\n"); >> - goto err; >> + goto err_free_all; >> } >> } >> >> return 0; >> >> +err_free_all: >> + i = DA7219_DAI_NUM_CLKS - 1; >> err: >> do { >> if (da7219->dai_clks_lookup[i]) > > This do while statement is wrong and it leads to potentially calling > clk_hw_unregister() on clks that haven't been registered. Obviously right. Thanks for the review Dan. I'll send a v2 in the coming days. CJ > > I think that calling clk_hw_unregister() on unregistered clocks is > supposed to okay but I found a case where it leads to a WARN_ON() > (Nothing else harmful). It's in __clk_register() if the alloc_clk() > fails: > > hw->clk = alloc_clk(core, NULL, NULL); > if (IS_ERR(hw->clk)) { > ret = PTR_ERR(hw->clk); > goto fail_create_clk; // <- forgot to set hw->clk = NULL > } > > The better way to handle errors from loops is to clean up partial > iterations before doing the goto. So add a clk_hw_unregister() if the > dai_clk_lookup = clkdev_hw_create() assignment fails. Then use a > while (--i >= 0) loop in the unwind section: > > err_free_all: > i = DA7219_DAI_NUM_CLKS; > err: > while (--i >= 0) { > > regards, > dan carpenter > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FAFDC48BC2 for ; Wed, 23 Jun 2021 21:14:50 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A1CC7610F7 for ; Wed, 23 Jun 2021 21:14:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1CC7610F7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=wanadoo.fr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 527CD844; Wed, 23 Jun 2021 23:13:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 527CD844 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1624482886; bh=7XvJIFpnQKdLxgbnMGNr7Ej2ama0m/2bvhgFYhOU29s=; h=Subject:To:References:From:Date:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Pwfueyzvp5ihwu8T0mTy9tmwPU1Mj5kCj6JbdKCHidNW37yELFVLEk3kHOd0Y4WVW 4I1InaCEJYbyfUL58XByvDumJHh9xjOsi00T5oFb3gAaALIh3Yb2IN/B2fNmYPoKaT RmQXDj33BG+zVNBQbeU2Cxs8hu+Eaam1yowKS5Ic= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id CFC82F80137; Wed, 23 Jun 2021 23:13:55 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id DF1EEF8016D; Wed, 23 Jun 2021 23:13:53 +0200 (CEST) Received: from smtp.smtpout.orange.fr (smtp11.smtpout.orange.fr [80.12.242.133]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9C225F80137 for ; Wed, 23 Jun 2021 23:13:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9C225F80137 Received: from [192.168.1.18] ([86.243.172.93]) by mwinf5d90 with ME id LlDn2500Q21Fzsu03lDnbG; Wed, 23 Jun 2021 23:13:49 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 23 Jun 2021 23:13:49 +0200 X-ME-IP: 86.243.172.93 Subject: Re: [PATCH] ASoC: da7219: Fix an out-of-bound read in an error handling path To: Dan Carpenter Newsgroups: gmane.linux.alsa.devel, gmane.linux.kernel, gmane.linux.kernel.janitors References: <4fdde55198294a07f04933f7cef937fcb654c901.1624425670.git.christophe.jaillet@wanadoo.fr> <20210623094655.GB2116@kadam> From: Christophe JAILLET Message-ID: <8e0d461a-c633-0162-b9e6-c2166bc013fe@wanadoo.fr> Date: Wed, 23 Jun 2021 23:13:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210623094655.GB2116@kadam> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Cc: alsa-devel@alsa-project.org, support.opensource@diasemi.com, lgirdwood@gmail.com, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, tiwai@suse.com, broonie@kernel.org, Adam.Thomson.Opensource@diasemi.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Le 23/06/2021 à 11:46, Dan Carpenter a écrit : > On Wed, Jun 23, 2021 at 07:22:45AM +0200, Christophe JAILLET wrote: >> If 'of_clk_add_hw_provider()' fails, the previous 'for' loop will have >> run completely and 'i' is know to be 'DA7219_DAI_NUM_CLKS'. >> >> In such a case, there will be an out-of-bounds access when using >> 'da7219->dai_clks_lookup[i]' and '&da7219->dai_clks_hw[i]'. >> >> To avoid that, add a new label, 'err_free_all', which set the expected >> value of 'i' in such a case. >> >> Fixes: 78013a1cf297 ("ASoC: da7219: Fix clock handling around codec level probe") >> Signed-off-by: Christophe JAILLET >> --- >> sound/soc/codecs/da7219.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c >> index 13009d08b09a..1e8b491d1fd3 100644 >> --- a/sound/soc/codecs/da7219.c >> +++ b/sound/soc/codecs/da7219.c >> @@ -2204,12 +2204,14 @@ static int da7219_register_dai_clks(struct snd_soc_component *component) >> da7219->clk_hw_data); >> if (ret) { >> dev_err(dev, "Failed to register clock provider\n"); >> - goto err; >> + goto err_free_all; >> } >> } >> >> return 0; >> >> +err_free_all: >> + i = DA7219_DAI_NUM_CLKS - 1; >> err: >> do { >> if (da7219->dai_clks_lookup[i]) > > This do while statement is wrong and it leads to potentially calling > clk_hw_unregister() on clks that haven't been registered. Obviously right. Thanks for the review Dan. I'll send a v2 in the coming days. CJ > > I think that calling clk_hw_unregister() on unregistered clocks is > supposed to okay but I found a case where it leads to a WARN_ON() > (Nothing else harmful). It's in __clk_register() if the alloc_clk() > fails: > > hw->clk = alloc_clk(core, NULL, NULL); > if (IS_ERR(hw->clk)) { > ret = PTR_ERR(hw->clk); > goto fail_create_clk; // <- forgot to set hw->clk = NULL > } > > The better way to handle errors from loops is to clean up partial > iterations before doing the goto. So add a clk_hw_unregister() if the > dai_clk_lookup = clkdev_hw_create() assignment fails. Then use a > while (--i >= 0) loop in the unwind section: > > err_free_all: > i = DA7219_DAI_NUM_CLKS; > err: > while (--i >= 0) { > > regards, > dan carpenter > >