From patchwork Wed Apr 26 09:12:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 87750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp105648vqo; Wed, 26 Apr 2023 02:13:55 -0700 (PDT) X-Google-Smtp-Source: AKy350bMiTIAlKcndgnqg7IXQtpBQCWBy+ibXsoAIHM+G8ZprKvKO0cutfn40Qvl5GsZ9+s9xVId X-Received: by 2002:a05:6a00:c88:b0:63b:7b29:46d7 with SMTP id a8-20020a056a000c8800b0063b7b2946d7mr26144359pfv.13.1682500435284; Wed, 26 Apr 2023 02:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682500435; cv=none; d=google.com; s=arc-20160816; b=GPmEcdhtoy7ODU6Sxas09biIYP9SRqtkRpVFWNFphiVmgaebMZPlA+cYW+iTmOSdw7 dNlkfN1VYbp6kDdwZZhwUBfhfAYGiESbLhvAPx0dxE3ynBKrxyuyu3h2RsPqex+/xw0x he5ByTvQTuVWS+is4nv8J1g4qh7mztbuT2ApobCM51KpxWlxQuMbXwOwJETdyZj6jYlg mOzEWEVneIUk6e/F4qehO/jEveo7Of2/N358wd6uGSE9pay+/wlwPKHWwQCMIgDYMxtg 5G1Yp+gzj66fa5I9NLuuHLkzX/giIbc+oOTkvNRKhp6JO8aaDESYedziqAHHgRTN1HA7 yd8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=GuxVjsoTXKU254LFESPJjHlOjjGGmyQlCK89QiYa1Mc=; b=LqRq584WhWFTbnkTQOK5E8jHW1GI/wD9jQRR/YGIOCB3RqxfCsiI2ZshhxoTrlf0HT T9/QixhzJRGE4IDBK/upFJ3gmzMy7gVEiunEaOL0HhP7wPu4bbs5hOm9RXkksZngnrIF qiAWDwm0oy+7CtthJnk6mye6kOb9BIH0lgykI7X73Kf6278GuqHMcpw5xV80YBCGeZY+ f29Kv6EZ9WQusnVAAfqBj1gHIo+2vYvyG3oFTDetzoNEciOT+gIlRZwQkY0C4gqP2/yG GPQ1k5TcYTe10Tz4/Ga202BswQK7GFd8qaEHgBP8ZjQTgphhilnIRvESXaq02oGS98RN DVkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=A43yC7y7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020aa79603000000b0063b82c09424si15713443pfg.151.2023.04.26.02.13.41; Wed, 26 Apr 2023 02:13:55 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=A43yC7y7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240027AbjDZJM7 (ORCPT + 99 others); Wed, 26 Apr 2023 05:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240021AbjDZJMe (ORCPT ); Wed, 26 Apr 2023 05:12:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13CAE186; Wed, 26 Apr 2023 02:12:33 -0700 (PDT) Date: Wed, 26 Apr 2023 09:12:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682500351; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuxVjsoTXKU254LFESPJjHlOjjGGmyQlCK89QiYa1Mc=; b=A43yC7y7Z7nqh1GriBaom01QU4fEEeQsRIWFzCzfNJDu5UFoCtgvMt41B/KemcphHEfTKo wUiIaFHKc9cRvFmcxvUrI/US0TtFcsXh8xVcFzv6JafWqK0eSfziwahlfu0c4xV9yK53Nd QJjKXjIb/nUM5zzkmqKcXJ0BJ/cVnEtVoJp4h53cPbr4M9CgeZvxv9FfyktR7ltD6nd8gS ZXd1fu97npiHd7KjFoPg8NLObtA8iC2uPHESqeIjuRT7HyXYfzCm7SAgdYdWTzGbvTaRRQ 6LT5+0iFsvPzeNiIJSbpzn7SQh/nOx1Kpzjp+jUQeq/hN4ab0KtoEjPNGcgz5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682500351; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuxVjsoTXKU254LFESPJjHlOjjGGmyQlCK89QiYa1Mc=; b=vbgr1vKXWUAGkYUbLOh6W3RfBQd2YKKDlPbWJWVaxMHZZs99AFRWs8zz2n7eSWaEJgTBz1 a0/ykiZpZ+v1PeCg== From: "tip-bot2 for Qinrun Dai" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] clocksource/drivers/davinci: Fix memory leak in davinci_timer_register when init fails Cc: Qinrun Dai , Daniel Lezcano , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230413135037.1505799-1-flno@hust.edu.cn> References: <20230413135037.1505799-1-flno@hust.edu.cn> MIME-Version: 1.0 Message-ID: <168250035114.404.784113346970013195.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764229576103700697?= X-GMAIL-MSGID: =?utf-8?q?1764229576103700697?= The following commit has been merged into the timers/core branch of tip: Commit-ID: fb73556386e074e9bee9fa2d253aeaefe4e063e0 Gitweb: https://git.kernel.org/tip/fb73556386e074e9bee9fa2d253aeaefe4e063e0 Author: Qinrun Dai AuthorDate: Thu, 13 Apr 2023 13:50:37 Committer: Daniel Lezcano CommitterDate: Mon, 24 Apr 2023 16:56:13 +02:00 clocksource/drivers/davinci: Fix memory leak in davinci_timer_register when init fails Smatch reports: drivers/clocksource/timer-davinci.c:332 davinci_timer_register() warn: 'base' from ioremap() not released on lines: 274. Fix this and other potential memory leak problems by adding a set of corresponding exit lables. Fixes: 721154f972aa ("clocksource/drivers/davinci: Add support for clockevents") Signed-off-by: Qinrun Dai Link: https://lore.kernel.org/r/20230413135037.1505799-1-flno@hust.edu.cn Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-davinci.c | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c index 9996c05..b1c2484 100644 --- a/drivers/clocksource/timer-davinci.c +++ b/drivers/clocksource/timer-davinci.c @@ -257,21 +257,25 @@ int __init davinci_timer_register(struct clk *clk, resource_size(&timer_cfg->reg), "davinci-timer")) { pr_err("Unable to request memory region\n"); - return -EBUSY; + rv = -EBUSY; + goto exit_clk_disable; } base = ioremap(timer_cfg->reg.start, resource_size(&timer_cfg->reg)); if (!base) { pr_err("Unable to map the register range\n"); - return -ENOMEM; + rv = -ENOMEM; + goto exit_mem_region; } davinci_timer_init(base); tick_rate = clk_get_rate(clk); clockevent = kzalloc(sizeof(*clockevent), GFP_KERNEL); - if (!clockevent) - return -ENOMEM; + if (!clockevent) { + rv = -ENOMEM; + goto exit_iounmap_base; + } clockevent->dev.name = "tim12"; clockevent->dev.features = CLOCK_EVT_FEAT_ONESHOT; @@ -296,7 +300,7 @@ int __init davinci_timer_register(struct clk *clk, "clockevent/tim12", clockevent); if (rv) { pr_err("Unable to request the clockevent interrupt\n"); - return rv; + goto exit_free_clockevent; } davinci_clocksource.dev.rating = 300; @@ -323,13 +327,27 @@ int __init davinci_timer_register(struct clk *clk, rv = clocksource_register_hz(&davinci_clocksource.dev, tick_rate); if (rv) { pr_err("Unable to register clocksource\n"); - return rv; + goto exit_free_irq; } sched_clock_register(davinci_timer_read_sched_clock, DAVINCI_TIMER_CLKSRC_BITS, tick_rate); return 0; + +exit_free_irq: + free_irq(timer_cfg->irq[DAVINCI_TIMER_CLOCKEVENT_IRQ].start, + clockevent); +exit_free_clockevent: + kfree(clockevent); +exit_iounmap_base: + iounmap(base); +exit_mem_region: + release_mem_region(timer_cfg->reg.start, + resource_size(&timer_cfg->reg)); +exit_clk_disable: + clk_disable_unprepare(clk); + return rv; } static int __init of_davinci_timer_register(struct device_node *np)