Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5332179rwr; Mon, 24 Apr 2023 02:26:13 -0700 (PDT) X-Google-Smtp-Source: AKy350bghR0POvLMBk+oZg4wJf6lt9Jzla1gUYw76iMxoVHCAsUZRjse3UNQ4Q46uSY3JqrvmUlI X-Received: by 2002:a05:6a20:548d:b0:f5:92f0:81e8 with SMTP id i13-20020a056a20548d00b000f592f081e8mr981711pzk.29.1682328373441; Mon, 24 Apr 2023 02:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682328373; cv=none; d=google.com; s=arc-20160816; b=MrH+E5FB33cfs7ZQR/SiMcMDEoaUZ5XjOgFvkerw12GmBzQnMKIl+e3VkkohOyutRv f5S2h6YOYp6ieBiOzFjvsUQeTx8+cshFNijacVyzN/Yv1yQi/WnjmPn6sTcLVqy+Yt0I 4nMhVcIGKgkAJOnOP1VD/DAnjl1nlHjc5ygAecu278cfEzvF+QPMZW9QqrtS8Yc6coCj ++d5p+EX7JyqPGXzu7TLNJTBxIUEG873ia1AzmYnb9CuEZBq72ytE7Msvzuneft5bgaE ecSqeZFLTFUdiNpR6kRFnToW09nYTe0c1tS20SET+LN0E8alCdhiD4cacQ+RjoJlS6GQ uOKw== 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=ujg50lAC9+et/agR3zc7+xUz3Nvee3NIzUYFJLVLzD4=; b=rNY8Bhl5kSp4xiX3OeyoonBvgdsrZaRYJDqV5mSh2S7wOW1n0t+c9wFKAugULPWjW3 /Yth/k7fTkkmLboIA7irVsvdr/vXG3JdiiGgGIrVD4/GgI0xkAc+iORvMgvI3REJcw/B pSi+VFwHpw9WjPh+ifBN9cMoufIMFIwgG6zWamtPuFaL/V7xokp6N1plCabyn8pR1UXN woYRj/5W1vxozozLOLVVbNBtQBAlkRYV1bOB3PwL0HkjdI0J+KiJDNWh8qy7JNMPrMKC sGImG+dx4HPPtoSEb/9NOBL89CBowp5GP+SeFTnrqDk+dJlbj2ac2IRk4NSechYmy/Ca OqeQ== 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 o3-20020a63fb03000000b005077dda047csi10880583pgh.803.2023.04.24.02.26.00; Mon, 24 Apr 2023 02:26:13 -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 S231405AbjDXJY7 (ORCPT + 99 others); Mon, 24 Apr 2023 05:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbjDXJY5 (ORCPT ); Mon, 24 Apr 2023 05:24:57 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F3D1B9; Mon, 24 Apr 2023 02:24:55 -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 33O9NnLa011810-33O9NnLb011810 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 24 Apr 2023 17:23:54 +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 1/2] clk: imx: clk-imx8mp: use dev_ managed memory to avoid memory leak in imx8mp_clocks_probe() Date: Mon, 24 Apr 2023 09:23:46 +0000 Message-Id: <20230424092346.124509-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 disassembled 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. 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 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c index 3253589851ff..353d58b665f9 100644 --- a/drivers/clk/imx/clk-imx8mp.c +++ b/drivers/clk/imx/clk-imx8mp.c @@ -416,23 +416,19 @@ static int imx8mp_clocks_probe(struct platform_device *pdev) void __iomem *anatop_base, *ccm_base; 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; -- 2.34.1