Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp424566rwr; Wed, 3 May 2023 00:09:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+q8RaSMYOsIPx7IGrPL6JdSwSCUiZSGOz5jwr8jbMf55JtG1JOOm0SY5NWpvthgsMIQBL X-Received: by 2002:a17:90b:4b90:b0:247:35c7:bd67 with SMTP id lr16-20020a17090b4b9000b0024735c7bd67mr20652504pjb.46.1683097762517; Wed, 03 May 2023 00:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683097762; cv=none; d=google.com; s=arc-20160816; b=dYCGIcVm9xvIg7gfZ5ACVA/ytZ9Cf6utPl0/C1yhcH7WDsJ8hxABHs9x1pU31W66eO Y+mC3JK7B5oDsRr5oLxW/X0QZ/xga8IMTJjhpkpg3O6wjWJIQtiAAU8PyrbrHWP6MkaS HU8m3XH/rszTVRwO19EMmQrPivr3nPljbJGxIQK3K4ELPiilpkBDbn6qLsCWJt2Y0hCh B91+HD2FJmM8vBvh11XWB053OVMsTxRAGwQ8Bfbr6cid12cN9GA6eRL9TQZ3IM9g8fUT wg4TFleSZIqCyYfdGuEg46DSv0Yzg1XGg8gjtvdUTPUh/pRGDt1jBjPC2dXgP7AmocY+ GxUw== 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=dZS33mYrN3SnmkhtVwkakrJjZXE7PEZgj2FY8cREaLE=; b=ep2/SFslK8L1vJEN3U+fw/p0xnpk/t9jDc2De9kdQMxwS7NpNGabIBnFfnjvvlQ0K0 C9D3p/Ng/7ad7/+fYO87kkmHJgqBP0tsHBWyxdiJZUrmIanbkuXhlpfiQI8J0W0AdDL+ wTbcQEWI5ZRxb4AWVCleqi5lqQf+mRsVKuYaXlWWlE1KR0ry7GU1jPgfhzNceUQm6set ihS660s1T8GQrtxqXDIz4RACKbOR0Rem/X/aGEPkKoupbZ9uQISRRVf+zdVwE5uHyuCK L1Bh1GPMMSpez+XL07GpqdAIJPp6lscFh1w8L5TL/oygdGAVqhhChYeLD7ZnUYHWJ6h3 lDWA== 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 ha2-20020a17090af3c200b0022c9cb7662csi864486pjb.159.2023.05.03.00.09.08; Wed, 03 May 2023 00:09:22 -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 S229528AbjECHIK (ORCPT + 99 others); Wed, 3 May 2023 03:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjECHIJ (ORCPT ); Wed, 3 May 2023 03:08:09 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 388161FF6; Wed, 3 May 2023 00:08:07 -0700 (PDT) Received: from liuyuxing.. ([10.12.190.56]) (user=lyx2022@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 343769xR010417-343769xS010417 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 3 May 2023 15:06:15 +0800 From: Yuxing Liu 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, Yuxing Liu , Dongliang Mu , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: imx: clk-imx8mp: improve error handling in imx8mp_clocks_probe() Date: Wed, 3 May 2023 07:06:07 +0000 Message-Id: <20230503070607.2462-1-lyx2022@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: lyx2022@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 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(); -- 2.34.1