From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 478E8C77B60 for ; Fri, 28 Apr 2023 03:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=n6LQhugAhybcYdR0G840nvo28z5VfT2InQUG4Jr4C4Y=; b=pc8H2++2HeFq7B BYjeGPqBs8H57ljmDmeQODadigee/jLuwMsz/RGfv5pPXVKXHCmDdbgcFycQBoeB8p52w1+TXp8RO 2FdLF4JOxGLpSDscAWSfQdyWmVPyWhx1KBcd7JVlUUqeys3oBfEZN1tvCrz2i8FnsMwFprN8y/Qzx R/TCEoaQ+dSNoc3K2u62wFewWUWWNefLXxe7zD5YSNoB3OSYmYmbo8Aha3ozWDZmHSSUq/+cKjDPB 6Z/9iDESXObDw8KOFrqH7pmcOIwy9G1N0JdCXEEDH19aBv5Cu8I0wfzxqr1IeDkrU9w5qdt1W2NF4 DT/lA/yQdwyDw2he3x7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1psEco-0083Uq-01; Fri, 28 Apr 2023 03:18:22 +0000 Received: from [202.114.0.240] (helo=hust.edu.cn) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1psEcZ-0083Ro-3C for linux-snps-arc@lists.infradead.org; Fri, 28 Apr 2023 03:18:20 +0000 Received: from localhost.localdomain ([172.16.0.254]) (user=m202171830@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33S3GctD016701-33S3GctE016701 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 28 Apr 2023 11:16:43 +0800 From: Ke Zhang To: Vineet Gupta , Greg Kroah-Hartman , Jiri Slaby , Rob Herring Cc: hust-os-kernel-patches@googlegroups.com, Ke Zhang , Dongliang Mu , Vineet Gupta , linux-snps-arc@lists.infradead.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] serial: arc_uart: fix of_iomap leak in `arc_serial_probe` Date: Fri, 28 Apr 2023 11:16:36 +0800 Message-Id: <20230428031636.44642-1-m202171830@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-FEAS-AUTH-USER: m202171830@hust.edu.cn X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230427_201808_421909_FA8162DF X-CRM114-Status: GOOD ( 10.59 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org Smatch reports: drivers/tty/serial/arc_uart.c:631 arc_serial_probe() warn: 'port->membase' from of_iomap() not released on lines: 631. In arc_serial_probe(), if uart_add_one_port() fails, port->membase is not released, which would cause a resource leak. To fix this, I replace of_iomap with devm_platform_ioremap_resource. Fixes: 8dbe1d5e09a7 ("serial/arc: inline the probe helper") Signed-off-by: Ke Zhang Reviewed-by: Dongliang Mu --- v1 -> v2: Use devm_platform_ioremap_resource() and return that errno if an errno was returned. This issue is found by static analysis and remains untested. --- drivers/tty/serial/arc_uart.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c index 59e25f2b6632..4b2512eef577 100644 --- a/drivers/tty/serial/arc_uart.c +++ b/drivers/tty/serial/arc_uart.c @@ -606,10 +606,11 @@ static int arc_serial_probe(struct platform_device *pdev) } uart->baud = val; - port->membase = of_iomap(np, 0); - if (!port->membase) + port->membase = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(port->membase)) { /* No point of dev_err since UART itself is hosed here */ - return -ENXIO; + return PTR_ERR(port->membase); + } port->irq = irq_of_parse_and_map(np, 0); -- 2.25.1 _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc