Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp271486rwl; Thu, 6 Apr 2023 19:01:03 -0700 (PDT) X-Google-Smtp-Source: AKy350YocmSN+9cCVyzfH4aUzPKRZsyhJOnSFuz0ZDH8zDF9EqwxdzIUyFnNeY3MCXm7i0Ng9hrC X-Received: by 2002:a17:906:4c52:b0:92f:7c42:8637 with SMTP id d18-20020a1709064c5200b0092f7c428637mr772641ejw.30.1680832862815; Thu, 06 Apr 2023 19:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680832862; cv=none; d=google.com; s=arc-20160816; b=S07UkGpUyKADEutb3iaD146KCJmVFNf4actEl46FnPsgXb3vUJwuVG0oFVTaFK0Rkx ue1+FJk3nwNH9TexkLZiwo/+/kO07Ahe6KNWTv9Trcu/h4swgXj9x1yTX82t5OmLLutr 0mc5q0NC3LKcpnykcyUTDhW0EVcuHCLNy3ffOEg7Ah/gdqn9Hsf/C1HVSqM6cKhq9bM6 5OOSomrrLMq6m6CgsLVcefMANKHkwpPYoIvJlP8+2K3x3PscRbPp6rh8P89JQdhEpKbC 6efhA8Rq5wc6Dhqss+Nso7RQe/KkKFYibyh1OMZDq0cxDQwVHfY/RnR5ci0TSTX6nvMW 1g1Q== 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=2fiMDND0dQhk7eUo6L2ngLwdZILSx//xWFADJ2LXJPM=; b=EQMs4ROwO58kn4gBkiVSDgSwNXydq/QUKqb3mLoyi7WIFaWtQA6SHW3Hk5kFZUpeCU uNiRS64Z/bw+ShSByboJ3iV02iwauVkoc27TvFMAY9QMZJrZKZqfoYmqcOl6bJL/daG1 wve3+EU4yuKHLuHxkGFV78xvhCCCZd9U/an1y9DuZGsRfqpaz8ceuydqyIo6mcBoUAIG Ehn7OvcNVa3hgaAnSITveq2z0ftVGSBZzXOsQd0Lg7QWL1rB/gv99mHzzwkiRB/LAPA0 ePkaZzGKfKjgOYV/5/fnVoAs7dC5UorzzX5mPx47T6SJq2VNkdPh/2KYP/dtLBzhjXmR C/7w== 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 qc27-20020a170906d8bb00b00930f903a752si1950142ejb.177.2023.04.06.19.00.37; Thu, 06 Apr 2023 19:01:02 -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 S239368AbjDGBqc (ORCPT + 99 others); Thu, 6 Apr 2023 21:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238742AbjDGBqa (ORCPT ); Thu, 6 Apr 2023 21:46:30 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 180056E82; Thu, 6 Apr 2023 18:46:28 -0700 (PDT) Received: from DESKTOP-DE31U50.localdomain ([10.12.190.69]) (user=m202171776@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 3371iIP2031817-3371iIP3031817 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 7 Apr 2023 09:44:21 +0800 From: Hao Luo 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, Hao Luo , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: imx: clk-imx8mn: fix memory leak in imx8mn_clocks_probe Date: Fri, 7 Apr 2023 09:44:14 +0800 Message-Id: <20230407014414.22237-1-m202171776@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: m202171776@hust.edu.cn X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 Use devm_platform_ioremap_resource() instead of of_iomap() to automatically handle the unused ioremap region. If any error occurs, regions allocated by kzalloc() will leak, but using devm_kzalloc() instead will automatically free the memory using devm_kfree(). Signed-off-by: Hao Luo --- drivers/clk/imx/clk-imx8mn.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c index a042ed3a9d6c..b054412f6373 100644 --- a/drivers/clk/imx/clk-imx8mn.c +++ b/drivers/clk/imx/clk-imx8mn.c @@ -323,7 +323,7 @@ static int imx8mn_clocks_probe(struct platform_device *pdev) void __iomem *base; int ret; - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MN_CLK_END), GFP_KERNEL); if (WARN_ON(!clk_hw_data)) return -ENOMEM; @@ -340,10 +340,10 @@ static int imx8mn_clocks_probe(struct platform_device *pdev) hws[IMX8MN_CLK_EXT4] = imx_get_clk_hw_by_name(np, "clk_ext4"); np = of_find_compatible_node(NULL, NULL, "fsl,imx8mn-anatop"); - base = of_iomap(np, 0); + base = devm_platform_ioremap_resource(pdev, 0); of_node_put(np); - if (WARN_ON(!base)) { - ret = -ENOMEM; + if (WARN_ON(IS_ERR(base))) { + ret = PTR_ERR(base); goto unregister_hws; } -- 2.34.1