diff mbox series

wifi: mt76: mt7915: fix memory leak in mt7915_mmio_wed_init_rx_buf

Message ID dc3c84f0ea8f9c7716fbd2619e69ac47cf277704.1672745677.git.lorenzo@kernel.org (mailing list archive)
State Superseded
Delegated to: Felix Fietkau
Headers show
Series wifi: mt76: mt7915: fix memory leak in mt7915_mmio_wed_init_rx_buf | expand

Commit Message

Lorenzo Bianconi Jan. 3, 2023, 11:38 a.m. UTC
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 <lorenzo@kernel.org>
---
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 mbox series

Patch

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;
 		}