Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp896073rwr; Wed, 26 Apr 2023 07:41:47 -0700 (PDT) X-Google-Smtp-Source: AKy350biUpuquC+PQib9DjyQtC5dUtp9lFjGsuzEphOH4NttI6D9b3zP9JrzQ5bs/RrlSBJdUrHU X-Received: by 2002:a17:90a:ac07:b0:247:2152:6391 with SMTP id o7-20020a17090aac0700b0024721526391mr20421796pjq.17.1682520107293; Wed, 26 Apr 2023 07:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682520107; cv=none; d=google.com; s=arc-20160816; b=MRQPcafrY4SRLVUMuLBE1PrvCCoY13cV2jvMaC4eKsLZ/Y2pWARUnCux5YUgib7rDK 39lzVPz0fTdZPxZEmm8llEmkfdI1kbOPKYQZwgcuGwLwy9HNrk96jKpjhY9DeXhkrie1 pnDwMObZcq3ley4pN47OKkgiQecljeqldnxsFjIXKZe87uXl0bpYe8p9dxW2MDkS+i1F Ct1UyfyL5ahUYNXL8+JjUECYpll7Rzy0myuxvIeHoTGGLJAx2oVPLM9EhJxAYPg3J6Dk lP3NjpvsWL/7CUC8bBOmTZk/m8936efgIYMzOddlzgtsQKYXm+53kGy6/4vlRgmc1i5l s5Mw== 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=oiflZtpI4y6+tkNJHl2jrUdCjD1mURVTlNSs05lgV9o=; b=c2SuKZs7Optl9d1SDhT3jj2wYXQZKP+63IcLpbXRWui5hQBlD3M+TFVM4Ey+SAEbER EymjmgAHYnDPmzuCkp3Y4QMa/GhVilr6s0bpguNW79H2UFQder0sCENS3Qn8iieqR5ku LXkhwnlHqQjv7h93re3CUEVDnTrQ351qd4V0/W03Nd/pwzrkjz4pmBQ5O9bdFWfQ7vlV izbil1U0C8cIxy3itk0d2glxNCe2aoE9jajCEQ4VYj7+PK26QWnagD8MqIw+RF8eGwLq CkGvps5T3QCg0i+yB+Lnnq0IrF5fM2PrdRJJlNTbdj5q3W34YmuC6XQPIoIBqGnq3H88 Sw0A== 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 v17-20020a634811000000b0051358b5c887si15180610pga.843.2023.04.26.07.41.35; Wed, 26 Apr 2023 07:41:47 -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 S240971AbjDZO16 (ORCPT + 99 others); Wed, 26 Apr 2023 10:27:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241368AbjDZO14 (ORCPT ); Wed, 26 Apr 2023 10:27:56 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C8CD7292; Wed, 26 Apr 2023 07:27:52 -0700 (PDT) Received: from hzh.. ([10.12.190.56]) (user=zero12113@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33QEPrKv018298-33QEPrKw018298 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 26 Apr 2023 22:25:58 +0800 From: Zhanhao Hu To: Abel Vesa , Peng Fan , Michael Turquette , Stephen Boyd , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: hust-os-kernel-patches@googlegroups.com, Zhanhao Hu , Dongliang Mu , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: imx93: fix memory leak and missing unwind goto in imx93_clocks_probe Date: Wed, 26 Apr 2023 14:25:52 +0000 Message-Id: <20230426142552.217435-1-zero12113@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: zero12113@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 In function probe(), it returns directly without unregistered hws when error occurs. I fix this by adding 'goto unregister_hws;' on line 295 and line 310. Besides, I use devm_kzalloc() instead of kzalloc() to automatically free the memory using devm_kfree() when error occurs. Similarly, I replace of_iomap() with devm_of_iomap() to automatically handle the unused ioremap region. So I delete 'iounmap(anatop_base);' in unregister_hws. Fixes: 24defbe194b6 ("clk: imx: add i.MX93 clk") Signed-off-by: Zhanhao Hu Reviewed-by: Dongliang Mu --- This issue is found by static analysis and remains untested. --- drivers/clk/imx/clk-imx93.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/clk/imx/clk-imx93.c b/drivers/clk/imx/clk-imx93.c index 07b4a043e449..b6c7c2725906 100644 --- a/drivers/clk/imx/clk-imx93.c +++ b/drivers/clk/imx/clk-imx93.c @@ -264,7 +264,7 @@ static int imx93_clocks_probe(struct platform_device *pdev) void __iomem *base, *anatop_base; int i, ret; - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX93_CLK_END), GFP_KERNEL); if (!clk_hw_data) return -ENOMEM; @@ -288,10 +288,12 @@ static int imx93_clocks_probe(struct platform_device *pdev) "sys_pll_pfd2", 1, 2); np = of_find_compatible_node(NULL, NULL, "fsl,imx93-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))) { + ret = PTR_ERR(base); + goto unregister_hws; + } clks[IMX93_CLK_ARM_PLL] = imx_clk_fracn_gppll_integer("arm_pll", "osc_24m", anatop_base + 0x1000, @@ -304,8 +306,8 @@ static int imx93_clocks_probe(struct platform_device *pdev) np = dev->of_node; base = devm_platform_ioremap_resource(pdev, 0); if (WARN_ON(IS_ERR(base))) { - iounmap(anatop_base); - return PTR_ERR(base); + ret = PTR_ERR(base); + goto unregister_hws; } for (i = 0; i < ARRAY_SIZE(root_array); i++) { @@ -345,7 +347,6 @@ static int imx93_clocks_probe(struct platform_device *pdev) unregister_hws: imx_unregister_hw_clocks(clks, IMX93_CLK_END); - iounmap(anatop_base); return ret; } -- 2.34.1