Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5413849rwd; Wed, 24 May 2023 01:06:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4oPIAZZuEVHjWZWRYs500dpeXuYmT3RFUZWWrcGkyPtWZ96So+j5O8EM0y4RcyoJBidIYB X-Received: by 2002:a17:902:e5cc:b0:1af:bcf7:2bd8 with SMTP id u12-20020a170902e5cc00b001afbcf72bd8mr8595893plf.52.1684915595188; Wed, 24 May 2023 01:06:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684915595; cv=none; d=google.com; s=arc-20160816; b=uM7nuXhesliHAKbP7QX3gYMrennUxdDyz/AtI/0Nv0WYyBAUcosW2TJJ/IVMth5yD6 lD6I0tRTtGsMBApQl8dNZtY6OTmLXJ5FhgtBlSHrBdCzLwhs2Gy4iknK7hR0ZkDwF57v rQ3R2ZgAu894vOXVJBLwAoEBdZz4sJdlVDD85E/Pm0PwKQF7RldIDELaveYK29btiAZR KpXPuujZJaZPTZitgA1lpW0wKpVTYjyqwQOJNP8YrwJyGw39LspUkRVMhjU3f9zPnHuT f/COOLKBKKW7zGdPq/4XmarOmVeG0SvGY1qcYgepeAtV3NMHQ1OjM7s3P+kj1fTS65Is WCcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=upHXMUPA7fyNjkx7s2VHFzQXPDvT0S3yW0BjY/EFzzE=; b=cF+d+pFcINn1WD97boGBTqDZQZ/2UOcAQKHO5XTx6HKWbCnwx3O9U1a7VBLGmY5tVI oLbNCcExtabnYNJYJ2XaVa+pYAppXPPYLjBokRyhQ2OlWZIRmq7E1erQPabYXxgrmxeZ YEJR/7nz9uEWqKNRf75mw7mlPFHuQMDSE2uO4Vihnm7vJwYTDG4Cfeq4yBC9JGyJus3t Gaa/f0iICNAy0XY3T08lc5891sSqw5OqOVL/ylgfATQieivrdk+AHN20BKhNVAtIen0S cUW2mQA6Zp1K4M0xfhOrDeehoGNegi2hABtnprXQZ2FjHBXy913NQhXfKUwdfQw/kog7 ckZQ== 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 w10-20020a170902e88a00b001a656596b9esi2279143plg.608.2023.05.24.01.06.22; Wed, 24 May 2023 01:06:35 -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 S239212AbjEXH54 (ORCPT + 99 others); Wed, 24 May 2023 03:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231432AbjEXH5z (ORCPT ); Wed, 24 May 2023 03:57:55 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7E4393; Wed, 24 May 2023 00:57:52 -0700 (PDT) Received: from [IPV6:2001:250:4000:511d:8894:e09e:de:de24] ([172.16.0.254]) (user=lyx2022@hust.edu.cn mech=PLAIN bits=0) by mx1.hust.edu.cn with ESMTP id 34O7rxBA003146-34O7rxBB003146 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Wed, 24 May 2023 15:53:59 +0800 Message-ID: <60946593-0df4-a131-fc4b-5c43b73df6ea@hust.edu.cn> Date: Wed, 24 May 2023 15:53:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] clk: imx: clk-imx8mp: improve error handling in imx8mp_clocks_probe() To: Abel Vesa , Peng Fan , Michael Turquette , Stephen Boyd , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Anson Huang Cc: hust-os-kernel-patches@googlegroups.com, Dongliang Mu , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20230503070607.2462-1-lyx2022@hust.edu.cn> From: Yuxing Liu In-Reply-To: <20230503070607.2462-1-lyx2022@hust.edu.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: lyx2022@hust.edu.cn X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 ping? 在 2023/5/3 15:06, Yuxing Liu 写道: > Replace of_iomap() and kzalloc() with devm_of_iomap() and devm_kzalloc() > which can automatically release the related memory when the device > or driver is removed or unloaded to avoid potential memory leak. > > In this case, iounmap(anatop_base) in line 427,433 are removed > as manual release is not required. > > Besides, referring to clk-imx8mq.c, check the return code of > of_clk_add_hw_provider, if it returns negtive, print error info > and unregister hws, which makes the program more robust. > > Fixes: 9c140d992676 ("clk: imx: Add support for i.MX8MP clock driver") > Signed-off-by: Yuxing Liu > Reviewed-by: Dongliang Mu > --- > This issue is found by static analysis and remains untested. > --- > drivers/clk/imx/clk-imx8mp.c | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c > index 3253589851ff..de7d2d2176be 100644 > --- a/drivers/clk/imx/clk-imx8mp.c > +++ b/drivers/clk/imx/clk-imx8mp.c > @@ -414,25 +414,22 @@ static int imx8mp_clocks_probe(struct platform_device *pdev) > struct device *dev = &pdev->dev; > struct device_node *np; > void __iomem *anatop_base, *ccm_base; > + int err; > > np = of_find_compatible_node(NULL, NULL, "fsl,imx8mp-anatop"); > - anatop_base = of_iomap(np, 0); > + anatop_base = devm_of_iomap(dev, np, 0, NULL); > of_node_put(np); > - if (WARN_ON(!anatop_base)) > - return -ENOMEM; > + if (WARN_ON(IS_ERR(anatop_base))) > + return PTR_ERR(anatop_base); > > np = dev->of_node; > ccm_base = devm_platform_ioremap_resource(pdev, 0); > - if (WARN_ON(IS_ERR(ccm_base))) { > - iounmap(anatop_base); > + if (WARN_ON(IS_ERR(ccm_base))) > return PTR_ERR(ccm_base); > - } > > - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL); > - if (WARN_ON(!clk_hw_data)) { > - iounmap(anatop_base); > + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL); > + if (WARN_ON(!clk_hw_data)) > return -ENOMEM; > - } > > clk_hw_data->num = IMX8MP_CLK_END; > hws = clk_hw_data->hws; > @@ -721,7 +718,12 @@ static int imx8mp_clocks_probe(struct platform_device *pdev) > > imx_check_clk_hws(hws, IMX8MP_CLK_END); > > - of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data); > + err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data); > + if (err < 0) { > + dev_err(dev, "failed to register hws for i.MX8MP\n"); > + imx_unregister_hw_clocks(hws, IMX8MP_CLK_END); > + return err; > + } > > imx_register_uart_clocks(); >