From nobody Thu Feb 12 10:35:17 2026 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 DAC23C7618E for ; Mon, 24 Apr 2023 12:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231596AbjDXMxs (ORCPT ); Mon, 24 Apr 2023 08:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbjDXMxq (ORCPT ); Mon, 24 Apr 2023 08:53:46 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A75EF123; Mon, 24 Apr 2023 05:53:45 -0700 (PDT) Received: from haru.localdomain ([10.12.176.125]) (user=m202071377@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33OCpkk5030859-33OCpkk6030859 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 24 Apr 2023 20:51:53 +0800 From: XuDong Liu To: Al Cooper , Broadcom internal kernel review list , Greg Kroah-Hartman , Jiri Slaby , Doug Berger , Florian Fainelli Cc: XuDong Liu , Dongliang Mu , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [Patch] serial: 8250_bcm7271: fix leak in `brcmuart_probe` Date: Mon, 24 Apr 2023 20:51:00 +0800 Message-Id: <20230424125100.4783-1-m202071377@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FEAS-AUTH-USER: m202071377@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/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:=20 'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032. In the function brcmuart_probe(), baud_mux_clk was not correctly released in subsequent error handling, which may cause memory leaks. To fix this issue, an error handling branch, err_clk_put, is added to release the variable using clk_put(), and an err_disable branch is added to meet the requirement of balancing clk_disable and clk_enable calls. Fixes: 15ac1122fd6d ("serial: 8250_bcm7271: Fix arbitration handling") Signed-off-by: XuDong Liu Reviewed-by: Dongliang Mu --- The issue is discovered by static analysis, and the patch is not tested yet. --- drivers/tty/serial/8250/8250_bcm7271.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_bcm7271.c b/drivers/tty/serial/82= 50/8250_bcm7271.c index f801b1f5b46c..b1670558868b 100644 --- a/drivers/tty/serial/8250/8250_bcm7271.c +++ b/drivers/tty/serial/8250/8250_bcm7271.c @@ -1023,7 +1023,7 @@ static int brcmuart_probe(struct platform_device *pde= v) dev_dbg(dev, "BAUD MUX clock found\n"); ret =3D clk_prepare_enable(baud_mux_clk); if (ret) - goto release_dma; + goto err_clk_put; priv->baud_mux_clk =3D baud_mux_clk; init_real_clk_rates(dev, priv); clk_rate =3D priv->default_mux_rate; @@ -1032,7 +1032,7 @@ static int brcmuart_probe(struct platform_device *pde= v) if (clk_rate =3D=3D 0) { dev_err(dev, "clock-frequency or clk not defined\n"); ret =3D -EINVAL; - goto release_dma; + goto err_clk_disable; } =20 dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not "); @@ -1119,6 +1119,10 @@ static int brcmuart_probe(struct platform_device *pd= ev) serial8250_unregister_port(priv->line); err: brcmuart_free_bufs(dev, priv); +err_clk_disable: + clk_disable_unprepare(baud_mux_clk); +err_clk_put: + clk_put(baud_mux_clk); release_dma: if (priv->dma_enabled) brcmuart_arbitration(priv, 0); --=20 2.34.1