Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4098442rwo; Tue, 25 Jul 2023 00:04:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlHSp219f6awrjS5XUEdO6Km/ewBUPXlDalJ2sCO6DtcvrmiUJ+L+mGjPmjj51J0LpQhWBBw X-Received: by 2002:a05:6e02:929:b0:348:d70e:b7f0 with SMTP id o9-20020a056e02092900b00348d70eb7f0mr1952151ilt.32.1690268640646; Tue, 25 Jul 2023 00:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690268640; cv=none; d=google.com; s=arc-20160816; b=BRlMLLjjxsSDSuh+cF+dnsUiLSYJ0urcftDvxuNxu0uHlZGrn2Jweow2TJsXUnUceA 7RURCktMIpXDCJGkStQrit103FnWlWIdAOT4b+Yvy4KbUTO2kMVmnWrSZnTlNBCJdw2S bdNBqdJQfBkq1ypoccPLX9xpt9U0kdvGJewB7FA8PKkhNj1AVjut/dhYmWK8Ojwap8xX CWVeGDJQn6CaEnJOndN4P/kgNawO5IycgWtQfFFSZOwoOYLtAlL0mR/e7dlrDAR4g8xM iN+yVr4l3xTpAlJiAenVdkY80+T052ziAhFyjiODDa458b9+1GLTViSm8nnd9Sy3SFGk oUjQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=s6jga3RjwkitHgwdCPnis9tgwBtIUKMPUOk6tyJ4mnU=; fh=BDDFGzP6DtAXrcnaNDA87KqSZT/NeOSnb+Ik/sQKV/g=; b=ewBFfYmPtUs9Ybihx8MBRNin1lAosOc4Hew06fs29w7s1fJD4ET3bN8m7TrnllmoEl ysj89Um6czCkAU4R7GScE3J5Tu86E8aVQKnBH5OGgujXROGS+3tAKAba6SCJ3Q06Rlk0 /UyrlJYYUrBZVUoPJGYvMhMlRIJkYfxe1/h4aBoE9mIRJMmBJKXRep0HFBrPrSfdLDkr BfZjwcPKjMfQ8CHEDS7fXDcut29BD5m7ROJZblEiVNKZjK6T+2Ja/IXIhbdPYeairq9u HFEFyM/VY2HCQJEcvx3E5RGQTtrHZTJLIr7OM2fsm3ZFg/aenz75O5Xz9bB11vWiC1xF qnPw== 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 h11-20020a63574b000000b0055c8b7f3523si11392623pgm.54.2023.07.25.00.03.48; Tue, 25 Jul 2023 00:04:00 -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 S232202AbjGYGmB (ORCPT + 99 others); Tue, 25 Jul 2023 02:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbjGYGl5 (ORCPT ); Tue, 25 Jul 2023 02:41:57 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DED721B0; Mon, 24 Jul 2023 23:41:55 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 36P6f9i2071443; Tue, 25 Jul 2023 14:41:09 +0800 (+08) (envelope-from Chunyan.Zhang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4R96p65DM4z2K4D5v; Tue, 25 Jul 2023 14:39:42 +0800 (CST) Received: from ubt.spreadtrum.com (10.0.73.70) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 25 Jul 2023 14:41:07 +0800 From: Chunyan Zhang To: Greg Kroah-Hartman , Jiri Slaby CC: , Baolin Wang , Orson Zhai , Chunyan Zhang , Chunyan Zhang , LKML Subject: [PATCH V3 2/2] serial: sprd: Fix DMA buffer leak issue Date: Tue, 25 Jul 2023 14:40:53 +0800 Message-ID: <20230725064053.235448-2-chunyan.zhang@unisoc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725064053.235448-1-chunyan.zhang@unisoc.com> References: <20230725064053.235448-1-chunyan.zhang@unisoc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.73.70] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 36P6f9i2071443 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, 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 Release DMA buffer when _probe() returns failure to avoid memory leak. Fixes: f4487db58eb7 ("serial: sprd: Add DMA mode support") Signed-off-by: Chunyan Zhang Reviewed-by: Baolin Wang --- V3: - Corresponding changes based on patch-1. V2: - Added Baolin's Reviewed-by; - Add setting rx_dma.virt to NULL after being freed. --- drivers/tty/serial/sprd_serial.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c index fc1377029021..99da964e8bd4 100644 --- a/drivers/tty/serial/sprd_serial.c +++ b/drivers/tty/serial/sprd_serial.c @@ -364,7 +364,7 @@ static void sprd_rx_free_buf(struct sprd_uart_port *sp) if (sp->rx_dma.virt) dma_free_coherent(sp->port.dev, SPRD_UART_RX_SIZE, sp->rx_dma.virt, sp->rx_dma.phys_addr); - + sp->rx_dma.virt = NULL; } static int sprd_rx_dma_config(struct uart_port *port, u32 burst) @@ -1203,7 +1203,7 @@ static int sprd_probe(struct platform_device *pdev) ret = uart_register_driver(&sprd_uart_driver); if (ret < 0) { pr_err("Failed to register SPRD-UART driver\n"); - return ret; + goto free_rx_buf; } } @@ -1222,6 +1222,7 @@ static int sprd_probe(struct platform_device *pdev) sprd_port[index] = NULL; if (--sprd_ports_num == 0) uart_unregister_driver(&sprd_uart_driver); +free_rx_buf: sprd_rx_free_buf(sport); return ret; } -- 2.41.0