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: 679721 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 68BDEC77B60 for ; Fri, 28 Apr 2023 03:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345099AbjD1DSb (ORCPT ); Thu, 27 Apr 2023 23:18:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345101AbjD1DSa (ORCPT ); Thu, 27 Apr 2023 23:18:30 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E512101; Thu, 27 Apr 2023 20:18:28 -0700 (PDT) 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 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.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);