Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4886437rwl; Mon, 10 Apr 2023 19:21:28 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXrPx+7pnYZk4ToDb7JHhafH6SXt8vdd87WwQeGhpMIgUe9ZcIsS8skwQ61Ti1L2AKSRvC X-Received: by 2002:a05:6402:489:b0:4fb:2296:30af with SMTP id k9-20020a056402048900b004fb229630afmr9950837edv.20.1681179688371; Mon, 10 Apr 2023 19:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681179688; cv=none; d=google.com; s=arc-20160816; b=v3kY0TDqsRmuo6J4+9mZtl4Svg2XOwGodKKhMOzCIPRDXpvHk/n1RmwqBVdGJsojcX mSRht+ClcarEnlPG554LFbl4vYrK4SCw0C7fZmBURefFqECZ/D63LGTEz5dleU/1mHD1 CTwhkFw5aov9wmWr0zgMX3fzwQ4qj05+Xh/Tk6BFLPHMqP4EBPvWBzqvRcz1UZFyl+fp r8CGMwMKLhUzjmZv0+l1mioYXKkK/TBR/YjGz3ZkNg85Cc9jF1hUXAQjGwEjZA9rDA00 pOmq5Lrbp6AWfA3InCr10DGdkLF2tk6hwGpTQJ2B/ZmwuPN1XvqH1YvqYK3gI7vekn4H sOJg== 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=OzJum/6vVudkoIEAS9NCALBStlng05t9KqjtxMAAZdk=; b=TA+MP3aCbtmr4fT7nmqNZ323KD3+c82qvou1qrkyRKxc6a0hkv2w7JYPpeQo9Vi483 FqWFcJZdmHcGFRY8eYjU/b3uYo57MY8sIE3zQRsMEnDZ9N+d9VoWdAubikNc7CvJyJop zwWWIZSNuBNzCgih3cgwrXkbtfDE6lWt9iQBp+5SaErKNUJtfDr7VJr69aB/ZDWb9TJM 2e8zrsxhZOCWU2AFA88ss1rrl4AlFxm6mKLftd+1BTNcpXvAm+I3rr+0EBskxkS56k5t 3Q7ImkCt5YroA6whNcbu1+KbtFK49y58nuj38L9zX1UndkCx6Wt+SQmnm0Fu61rs/tZU Wu4g== 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 a10-20020aa7cf0a000000b004ad06322427si761741edy.9.2023.04.10.19.20.59; Mon, 10 Apr 2023 19:21:28 -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 S229950AbjDKBwg (ORCPT + 99 others); Mon, 10 Apr 2023 21:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbjDKBwe (ORCPT ); Mon, 10 Apr 2023 21:52:34 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 843CCE67; Mon, 10 Apr 2023 18:52:33 -0700 (PDT) Received: from DESKTOP-DE31U50.localdomain ([10.12.190.56]) (user=m202171776@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33B1p8AW016919-33B1p8AX016919 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 11 Apr 2023 09:51:12 +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 , Anson Huang Cc: hust-os-kernel-patches@googlegroups.com, Hao Luo , Dongliang Mu , 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: Tue, 11 Apr 2023 09:51:07 +0800 Message-Id: <20230411015107.2645-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_of_iomap() 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(). Fixes: daeb14545514 ("clk: imx: imx8mn: Switch to clk_hw based API") Fixes: 96d6392b54db ("clk: imx: Add support for i.MX8MN clock driver") Signed-off-by: Hao Luo Reviewed-by: Dongliang Mu --- The issue is discovered by static analysis, and the patch is not tested yet. --- 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..569b2abf4052 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_of_iomap(dev, np, 0, NULL); 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