From patchwork Fri Apr 28 03:16:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ke Zhang X-Patchwork-Id: 1774707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=pc8H2++2; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q6yVT03F1z23td for ; Fri, 28 Apr 2023 13:18:25 +1000 (AEST) 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-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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. Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS 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: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.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);