Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5552722rwr; Mon, 24 Apr 2023 06:04:09 -0700 (PDT) X-Google-Smtp-Source: AKy350ZmXRzAzBSyPpO1ANZQBkyiQ7VxFZ+7a4/YPubvdRLVJQ2XfRWVQeXjSpJhPBCOdR1haK6q X-Received: by 2002:a05:7500:218a:b0:102:d94f:2322 with SMTP id g10-20020a057500218a00b00102d94f2322mr505390gac.36.1682341449402; Mon, 24 Apr 2023 06:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682341449; cv=none; d=google.com; s=arc-20160816; b=lIQ+UF9DmEun6zEjqS40j7yZ6b5KBJXl8DcEjBXTi6XOtMiK7t2lfJzQiV639wj4eZ DHAusXuYwq9wKyvRayKsBXFadWPnW14z0FxZRlEmAX0qwvvtVNpIP6eFJfEQTwJux6AJ DfI6Q16GfWCE8vO1x7FY/qBaDOZgrYzMo/+Of2r9vtIRN6OCldiNQKiFw8kjW9tUqQJd KJpgxoeHzcUABPToq1uMY9U1ZH4QAdy8QLmQwOVsZXGhOx3mw9jMCXAnHcDv/t+JZPTi VOhx9xZfJGQ9SbAggPzXllZf5Gk+HjJ4uOwOSzcHzVg+26behfU/umUEuE8qMT7kTOSK ylkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=G+FMxoEUz9OdWTvICTzgE/g1bYOkLfnnPNMUpp4iRDs=; b=AOHiqGU+T2o6HDoD+XLbH0hOLHwg8mIKVUy/22WCOluvC7LvmiH3zkZ/gN4mYM83+M mqVSc32qzd9SdkWFw8oXiS8xoVKS7xd8id9jJnSYgpinm9I6H7Os9k+Xel8HP8Fphdqz Hz1Mde8NazDBQHPqOnmgzsOFvv1+scp0ZYxohZoB8P8/L3bJ44qmovIM4xu3NwgbmpBr YO0MhAa3FiF2GNYzptsuxjlFkB53qF6kKQFS5QSsChQyQUfvw6KjAB9ywlX2pzOrEHwq 6u2PqqZt2NRt3zJSmrQEAQMynVcG6md9VGfzyHRD8mT+mhQj7tHRBVwOQUBB9qXoSgBQ 86ig== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j40-20020a0561023e2800b0042e62447153si1883324vsv.211.2023.04.24.06.03.44; Mon, 24 Apr 2023 06:04:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231351AbjDXMxr (ORCPT + 99 others); Mon, 24 Apr 2023 08:53:47 -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: 8bit X-FEAS-AUTH-USER: m202071377@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Smatch reports: drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn: '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/8250/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 *pdev) dev_dbg(dev, "BAUD MUX clock found\n"); ret = clk_prepare_enable(baud_mux_clk); if (ret) - goto release_dma; + goto err_clk_put; priv->baud_mux_clk = baud_mux_clk; init_real_clk_rates(dev, priv); clk_rate = priv->default_mux_rate; @@ -1032,7 +1032,7 @@ static int brcmuart_probe(struct platform_device *pdev) if (clk_rate == 0) { dev_err(dev, "clock-frequency or clk not defined\n"); ret = -EINVAL; - goto release_dma; + goto err_clk_disable; } dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not "); @@ -1119,6 +1119,10 @@ static int brcmuart_probe(struct platform_device *pdev) 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); -- 2.34.1