Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2033818rwj; Sun, 18 Dec 2022 21:19:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf7q9GqNfK0t0RkbDioitml4q2JGKguqLN+NnUXCv4/HEkWbxoy54C1Dnx+uqQuFpy4JuXe1 X-Received: by 2002:a05:6a20:699b:b0:a3:22f3:27ca with SMTP id t27-20020a056a20699b00b000a322f327camr57999297pzk.56.1671427172970; Sun, 18 Dec 2022 21:19:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671427172; cv=none; d=google.com; s=arc-20160816; b=UsmN6utNxbwf/6ivq6CQP2JtVHHI1xrbIUlcQToJBTl6na5NN0yivEaj6j8tXbtS7j cTVg7nxuciBX89peIqLyvZ3aCAGibQSqGu/R6I7YvLkXjzH814Zj4xsGO5SOfPcnU5Ku nucJQ1TSPAz4bcmeFULmEP0yWyka5rbunCpBd3tnOL1bEQQAtDZ2VsTRdBmrLP4vg870 mfOBLHUafXJWoUcYwxitGRJ3zXjLjFlb+EsMuDiEIEmlodP6DSPuB8fdUxiE3sLuNRvb 1qrjt7TnQ9YiTm+vzpzJGU9rAfAHOLrDpgbO/DWDyxkmB7mwIxYqIoxOSQuI3YIX+zzu zR0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=xGTZi6VmOFcWr4cuW00ZdwUqVgHtzUi+7zZ9/GhuAWY=; b=OaPeDFKjUHbhdOm+kRWShdo52zWWAClvfoVwDjb4hOcp1t5BaCKtRmh8CPgRfIqfh1 L3gIdol3jti05cdljUGVaf1mR86sYHnfamOjJ5nYzty/sJQxCLJk09xK9Lj3pmbYijXS koTwzo8KEwyy3Qj7FV+uHkrTxwiWkoJbxhsXS7g/NkOmmSgChdtcJbBDjqFOgNql7v89 n8O7TFPkqfI4YT1uG58aXHjGcDhmcX/uG55zXZQAaAL+dPER5zfQFGyM6rCYURucEtPx LnHdQCmkkkZWOa4BIy3b1zJQmhec7O9rYbFNZm7yxJPXhSw1j6fPGbTcUUwWei1ZkytE GryA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=d9NVy6TC; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r37-20020a632065000000b00478e15039c0si9921689pgm.779.2022.12.18.21.19.18; Sun, 18 Dec 2022 21:19:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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; dkim=pass header.i=@mediatek.com header.s=dk header.b=d9NVy6TC; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbiLSEsW (ORCPT + 66 others); Sun, 18 Dec 2022 23:48:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiLSEsT (ORCPT ); Sun, 18 Dec 2022 23:48:19 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB48DA1A5 for ; Sun, 18 Dec 2022 20:48:11 -0800 (PST) X-UUID: e1baa71bb333437b9c51a713a60d3c2d-20221219 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=xGTZi6VmOFcWr4cuW00ZdwUqVgHtzUi+7zZ9/GhuAWY=; b=d9NVy6TC417SlhIWWbgd4RA9Kbyhtp1TOCE5PIqjF8yKOd/DCFzb3OUOV9BWBel08ACcbIT3WsUMKqiFPAuw/M07+KFVPRLDvge5FBw0FPCjx0ZxuSOylBQZdtfQyvzycLRH/OKmbgUqD3qPOpP56OpdSMCqJ1MxzhSLCAaNYnM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14,REQID:a9f72236-872f-4029-ab8c-9e5312e8ee45,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:dcaaed0,CLOUDID:32ddb889-8530-4eff-9f77-222cf6e2895b,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: e1baa71bb333437b9c51a713a60d3c2d-20221219 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1039234005; Mon, 19 Dec 2022 12:48:09 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.186) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Mon, 19 Dec 2022 12:48:08 +0800 Received: from mcddlt001.gcn.mediatek.inc (10.19.240.15) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Mon, 19 Dec 2022 12:48:07 +0800 From: Bo Jiao To: Felix Fietkau CC: linux-wireless , Ryder Lee , Sujuan Chen , Shayne Chen , Evelyn Tsai , linux-mediatek , Bo Jiao Subject: [PATCH v2] wifi: mt76: fix potential memory leakage Date: Mon, 19 Dec 2022 12:48:04 +0800 Message-ID: <0a218783098a6b1b90ff120c7182acee93dc8feb.1671423784.git.Bo.Jiao@mediatek.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY autolearn=no 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-wireless@vger.kernel.org From: Bo Jiao fix potential memory leakage, recycle rxwi when mt76_dma_add_buf() call fail. Signed-off-by: Bo Jiao --- v2: - recycle rxwi when page_frag_alloc() and dma_map_single() fail. --- drivers/net/wireless/mediatek/mt76/dma.c | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index fc24b35..76ad47d 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -580,24 +580,29 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) buf = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC); if (!buf) - break; + goto out; addr = dma_map_single(dev->dma_dev, buf, len, DMA_FROM_DEVICE); - if (unlikely(dma_mapping_error(dev->dma_dev, addr))) { - skb_free_frag(buf); - break; - } + if (unlikely(dma_mapping_error(dev->dma_dev, addr))) + goto free; qbuf.addr = addr + offset; qbuf.len = len - offset; qbuf.skip_unmap = false; - if (mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t) < 0) { - dma_unmap_single(dev->dma_dev, addr, len, - DMA_FROM_DEVICE); - skb_free_frag(buf); - break; - } + if (mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t) < 0) + goto umap; + frames++; + continue; + +umap: + dma_unmap_single(dev->dma_dev, addr, len, + DMA_FROM_DEVICE); +free: + skb_free_frag(buf); +out: + mt76_put_rxwi(dev, t); + break; } if (frames) -- 2.18.0