From patchwork Tue Jan 3 11:38:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13087403 X-Patchwork-Delegate: nbd@nbd.name 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 67109C46467 for ; Tue, 3 Jan 2023 11:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230320AbjACLjP (ORCPT ); Tue, 3 Jan 2023 06:39:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237508AbjACLiy (ORCPT ); Tue, 3 Jan 2023 06:38:54 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88BB7BEE for ; Tue, 3 Jan 2023 03:38:51 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 243F561290 for ; Tue, 3 Jan 2023 11:38:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35A9EC433D2; Tue, 3 Jan 2023 11:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672745930; bh=9d+ZA9+UUUJ7cVDHm3Lvj5TBD1ROiI4HuptlEBA5qGU=; h=From:To:Cc:Subject:Date:From; b=BzZg/Xz2o5rhf0z3/BwaPtcAIhWC5ZHY/a0hq9QXQ7d2Rezlhg+Ecn901XCHr8zk4 vyfaH+0h0T6j13hmxvVw6/AweKVrbVuWEInOnC14fuz8+lTaxgA+somw9j9xdjZnDj cFviAFKDWctAW1LEqe0muZZt0yiKXM+zpgr690scSe387lZAOoxSIcpTP1EHJLxfZl mGzqThuNRxntQ4JQYNwRDY3d4GYdqmjFTbc9Z5htaFNr84aMnbZ9DwRaX5HttpDLes Uzp7jST8o/A6l+UZR0tzfK8GwRAKxgAOTzkdgj2VMJliAkS4zHyEK6CJ+5a621E16O yxI1AoN/gk6kg== From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH] wifi: mt76: mt7915: fix memory leak in mt7915_mmio_wed_init_rx_buf Date: Tue, 3 Jan 2023 12:38:39 +0100 Message-Id: X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Free mt76_txwi_cache pointer in mt7915_mmio_wed_init_rx_buf routine in case of failure. Fixes: 4f831d18d12d ("wifi: mt76: mt7915: enable WED RX support") Signed-off-by: Lorenzo Bianconi --- This patch is based of the following patch: https://lore.kernel.org/linux-wireless/3a5bef05c0e70f1e13ff4b9cc3d6a62fca8dc810.1672574310.git.lorenzo@kernel.org/ --- drivers/net/wireless/mediatek/mt76/mt7915/mmio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c index 757c2e25c25f..c0e7b30dfd48 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c @@ -628,9 +628,14 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) int token; void *ptr; + if (!t) + goto unmap; + page = __dev_alloc_page(GFP_KERNEL); - if (!page) + if (!page) { + mt76_put_rxwi(&dev->mt76, t); goto unmap; + } ptr = page_address(page); phy_addr = dma_map_single(dev->mt76.dma_dev, ptr, @@ -638,6 +643,7 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) DMA_TO_DEVICE); if (unlikely(dma_mapping_error(dev->mt76.dev, phy_addr))) { __free_page(page); + mt76_put_rxwi(&dev->mt76, t); goto unmap; } @@ -647,6 +653,7 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) dma_unmap_single(dev->mt76.dma_dev, phy_addr, wed->wlan.rx_size, DMA_TO_DEVICE); __free_page(page); + mt76_put_rxwi(&dev->mt76, t); goto unmap; }