Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3270040rwr; Sat, 22 Apr 2023 01:56:57 -0700 (PDT) X-Google-Smtp-Source: AKy350bTupKwNPewwUJME+nCcSJjy3NW9zMHSTfpuOVsd4OLdI1cNUZEL+uPXeIMZqcMl2YYQ1JZ X-Received: by 2002:a05:6a20:5496:b0:f1:f884:f0dd with SMTP id i22-20020a056a20549600b000f1f884f0ddmr9600207pzk.2.1682153817470; Sat, 22 Apr 2023 01:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682153817; cv=none; d=google.com; s=arc-20160816; b=b7m5YxIjSbcqOdqSaDReq4dbBmhiVN+EinFG1D4UpHLrVI03RtJHbA7cKiFR0gzoPu LJ76s6TNlBILpnIc0UHQqoDywlBNaNbHzMw4vVVszP4JEA7rRvslN4SzK9+rnddnebao EnDyDw4Np+jyNRgb6fbgkrfZePvkwxrgsns/tW5hn5e81XH7gNxskhPYRA1AI9u7AAPQ N1RuOC7UCc9I3a/E12ilurrgG8lDgdqNqqkhlIWi+1OqFvXyAW9k1bupGvTQcdbgVCGE pEsmabnzF95lBOuZoGzUrN48KLVDxoyYb6UcznOicSNAegcMb0O+LjHQUZw05eTMNy78 HlWQ== 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=I0xpDAQ4nhM386AE3+mUSIn2XzWMwxezXewy+n1I2H4=; b=ddD2rKc7/8QDlypS/lxqRUKKOzeMFK0vagYy1fgwtaYwtiV9RTlm7XIeG2RJdJuhUd 013vMdx652xOjmKfwClIEpP9eaKlx54nzS0AAIsiUNG4mk0jvSzhAMnPBNppEr7Dp+44 9Hww225JqrQQuB2dAl9+qkvff+R2EjZXKKs/260zcmBEHRPBkRg43ggVYVKN2zy6WFUr EaBrjupFpHKU1Jxfa2afpGo3e84BQRgXsATCW312EwkxS33q5Ur7F2sv1h12GH7wbwSc 3vU0EMq+5xUWMACmgquwBB0is+qWnMzrty41Qbws6qTfp6uIE3FkJieA/iRohqwu0so9 VwDQ== 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 v187-20020a632fc4000000b0050f55427e3dsi6529226pgv.701.2023.04.22.01.56.43; Sat, 22 Apr 2023 01:56:57 -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 S229565AbjDVIqz (ORCPT + 99 others); Sat, 22 Apr 2023 04:46:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjDVIqx (ORCPT ); Sat, 22 Apr 2023 04:46:53 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97AC719AD; Sat, 22 Apr 2023 01:46:52 -0700 (PDT) Received: from bosi.. ([10.12.190.56]) (user=u201911157@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33M8i4Mk027977-33M8i4Ml027977 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 22 Apr 2023 16:44:14 +0800 From: Bosi Zhang To: Michael Turquette , Stephen Boyd , Matthias Brugger , AngeloGioacchino Del Regno , Ikjoon Jang , Weiyi Lu , Chun-Jie Chen Cc: hust-os-kernel-patches@googlegroups.com, Bosi Zhang , Dongliang Mu , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH] clk: mediatek: fix of_iomap memory leak Date: Sat, 22 Apr 2023 08:43:31 +0000 Message-Id: <20230422084331.47198-1-u201911157@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: u201911157@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 Smatch reports: drivers/clk/mediatek/clk-mtk.c:583 mtk_clk_simple_probe() warn: 'base' from of_iomap() not released on lines: 496. This problem was also found in linux-next. In mtk_clk_simple_probe(), base is not released when handling errors if clk_data is not existed, which may cause a leak. So free_base should be added here to release base. Fixes: c58cd0e40ffa ("clk: mediatek: Add mtk_clk_simple_probe() to simplify clock providers") Signed-off-by: Bosi Zhang Reviewed-by: Dongliang Mu --- The issue is found by static analysis and remains untested. --- drivers/clk/mediatek/clk-mtk.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index fd2214c3242f..3c50f48e93a7 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -500,8 +500,10 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev, num_clks += mcd->num_mux_clks + mcd->num_divider_clks; clk_data = mtk_alloc_clk_data(num_clks); - if (!clk_data) - return -ENOMEM; + if (!clk_data) { + r = -ENOMEM; + goto free_base; + } if (mcd->fixed_clks) { r = mtk_clk_register_fixed_clks(mcd->fixed_clks, @@ -599,6 +601,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev, mcd->num_fixed_clks, clk_data); free_data: mtk_free_clk_data(clk_data); +free_base: if (mcd->shared_io && base) iounmap(base); return r; -- 2.34.1