Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp623102rwp; Wed, 12 Jul 2023 20:35:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlG6VP6gB6oF31JgXRBTCNvq/6MZg++XbMGpghBigVWAWPOzBTMTJRQo7WA6v7Bp4MBrN3nW X-Received: by 2002:a05:6a20:7d9a:b0:132:cf6e:c5d9 with SMTP id v26-20020a056a207d9a00b00132cf6ec5d9mr438367pzj.6.1689219345400; Wed, 12 Jul 2023 20:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689219345; cv=none; d=google.com; s=arc-20160816; b=p2urvhkssNrmr6WovsS4aGizLhy29NjKDMbBiRU6w8FfJZxejpkat2997c2mwk0WKj D8he44iqfIrQTZG7vaCYFJcEEy2efyiugbcj3J0c8VW6K2oGQo5sT60W5fb1BtCLjhRn 1lnzZ8sueEh2z0r9AuNn9TEw2S8O7wtCD7Sgap5jflysa5Y7LkS09NT898dlydPIM0U8 5vtI3BL5IHxYUlOpJumKekfWnibPlLoX7Vw+VrVBJndkyhRnhdS0ESKY+d5XUKPmVSR5 BW3MBP/TydZrUMQI7GSSRSWIZS1BTOs1tqE0AzMdUxGqka3cjQ1Ty8LD4SVS9TYeG5Vq moHg== 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=CEmXwyNwd4XKMo1xac0EK5CWNbp4Hl6ScdpE+Dt5yuY=; fh=BDDFGzP6DtAXrcnaNDA87KqSZT/NeOSnb+Ik/sQKV/g=; b=s39H1jChCXVJP+d6l4j0hRm9ek8ZDQk3wQWF1Itglsu6SCv9F0817YScj0EpwF0puE au3KVu1yagg/jpcKKnqLSPpR5iyIoBhoi4j29KlMXvmgrV4FnaZysQXB3W/GzmzUeQTs Cu9eUzd7fHQ5LCk9PHjvb6N01jvR+HWonMEtljoYMXN+Uus9Wabs0PZ6UdbKu9vnaOSZ jEEXusHAOEzLD/BwRPi59015ztVVqhS5PdWvz0k54eOpB3qH2pfSO9SDtcdtMDq/wOSa VgXx2TlzGr+6fiS7G0fJr3SFCj05sdYxilm1A3zmXg4I4HvEW8hY+hUB00T9prUKtZTq KWEA== 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 y16-20020a17090264d000b001b8b2cb7359si4378746pli.627.2023.07.12.20.35.31; Wed, 12 Jul 2023 20:35:45 -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 S233555AbjGMDUI (ORCPT + 99 others); Wed, 12 Jul 2023 23:20:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233500AbjGMDT7 (ORCPT ); Wed, 12 Jul 2023 23:19:59 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524AF1FEE; Wed, 12 Jul 2023 20:19:56 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 36D3JLrk061809; Thu, 13 Jul 2023 11:19:21 +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 4R1fvF2cfYz2M4K4c; Thu, 13 Jul 2023 11:18:17 +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; Thu, 13 Jul 2023 11:19:19 +0800 From: Chunyan Zhang To: Greg Kroah-Hartman , Jiri Slaby CC: , Baolin Wang , Orson Zhai , Chunyan Zhang , Chunyan Zhang , LKML Subject: [PATCH V2 2/2] serial: sprd: Fix DMA buffer leak issue Date: Thu, 13 Jul 2023 11:19:04 +0800 Message-ID: <20230713031904.12106-2-chunyan.zhang@unisoc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713031904.12106-1-chunyan.zhang@unisoc.com> References: <20230713031904.12106-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 36D3JLrk061809 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,MAY_BE_FORGED, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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, also set rx_dma.virt to NULL after being freed. Fixes: f4487db58eb7 ("serial: sprd: Add DMA mode support") Signed-off-by: Chunyan Zhang Reviewed-by: Baolin Wang --- V2: - Added Baolin's Reviewed-by; - Add setting rx_dma.virt to NULL after being freed. --- drivers/tty/serial/sprd_serial.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c index 11de338a6122..29d89751b3bb 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; } } sprd_ports_num++; @@ -1222,7 +1222,8 @@ static int sprd_probe(struct platform_device *pdev) sprd_port[index] = NULL; sprd_ports_num--; uart_unregister_driver(&sprd_uart_driver); - sprd_remove(pdev); +free_rx_buf: + sprd_rx_free_buf(sport); return ret; } -- 2.41.0