From nobody Tue Dec 16 16:39:13 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 519ADC77B61 for ; Tue, 25 Apr 2023 06:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233224AbjDYG7t (ORCPT ); Tue, 25 Apr 2023 02:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233309AbjDYG7p (ORCPT ); Tue, 25 Apr 2023 02:59:45 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C03E0AD39 for ; Mon, 24 Apr 2023 23:59:05 -0700 (PDT) Received: from Fengmx.. ([10.12.190.56]) (user=m202271825@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33P6umZx009583-33P6uma0009583 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 25 Apr 2023 14:56:53 +0800 From: Feng Mingxi To: Michal Simek , Daniel Lezcano , Thomas Gleixner , =?UTF-8?q?S=C3=B6ren=20Brinkmann?= Cc: hust-os-kernel-patches@googlegroups.com, Feng Mingxi , Dongliang Mu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clocksource: cadence-ttc: fix memory leak in ttc_timer_probe Date: Tue, 25 Apr 2023 06:56:11 +0000 Message-Id: <20230425065611.702917-1-m202271825@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FEAS-AUTH-USER: m202271825@hust.edu.cn Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Smatch reports: drivers/clocksource/timer-cadence-ttc.c:529 ttc_timer_probe() warn: 'timer_baseaddr' from of_iomap() not released on lines: 498,508,516. timer_baseaddr may have the problem of not being released after use, I replaced it with the devm_of_iomap() function and added the clk_put() function to cleanup the "clk_ce" and "clk_cs". Fixes: e932900a3279 ("arm: zynq: Use standard timer binding") Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init functio= n to return error") Signed-off-by: Feng Mingxi Reviewed-by: Dongliang Mu Acked-by: Michal Simek --- The issue is discovered by static analysis, and the patch is not tested yet. --- drivers/clocksource/timer-cadence-ttc.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/= timer-cadence-ttc.c index 4efd0cf3b602..0d52e28fea4d 100644 --- a/drivers/clocksource/timer-cadence-ttc.c +++ b/drivers/clocksource/timer-cadence-ttc.c @@ -486,10 +486,10 @@ static int __init ttc_timer_probe(struct platform_dev= ice *pdev) * and use it. Note that the event timer uses the interrupt and it's the * 2nd TTC hence the irq_of_parse_and_map(,1) */ - timer_baseaddr =3D of_iomap(timer, 0); - if (!timer_baseaddr) { + timer_baseaddr =3D devm_of_iomap(&pdev->dev, timer, 0, NULL); + if (IS_ERR(timer_baseaddr)) { pr_err("ERROR: invalid timer base address\n"); - return -ENXIO; + return PTR_ERR(timer_baseaddr); } =20 irq =3D irq_of_parse_and_map(timer, 1); @@ -513,20 +513,27 @@ static int __init ttc_timer_probe(struct platform_dev= ice *pdev) clk_ce =3D of_clk_get(timer, clksel); if (IS_ERR(clk_ce)) { pr_err("ERROR: timer input clock not found\n"); - return PTR_ERR(clk_ce); + ret =3D PTR_ERR(clk_ce); + goto put_clk_cs; } =20 ret =3D ttc_setup_clocksource(clk_cs, timer_baseaddr, timer_width); if (ret) - return ret; + goto put_clk_ce; =20 ret =3D ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq); if (ret) - return ret; + goto put_clk_ce; =20 pr_info("%pOFn #0 at %p, irq=3D%d\n", timer, timer_baseaddr, irq); =20 return 0; + +put_clk_ce: + clk_put(clk_ce); +put_clk_cs: + clk_put(clk_cs); + return ret; } =20 static const struct of_device_id ttc_timer_of_match[] =3D { --=20 2.34.1