Skip to content

Commit e5c3ac8

Browse files
LorenzoBianconiKalle Valo
authored andcommitted
wifi: mt76: handle possible mt76_rx_token_consume failures
Take into account possible error conditions of mt76_rx_token_consume routine in mt7915_mmio_wed_init_rx_buf() and mt76_dma_add_buf() Fixes: cd372b8 ("wifi: mt76: add WED RX support to mt76_dma_{add,get}_buf") Fixes: 4f831d1 ("wifi: mt76: mt7915: enable WED RX support") Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Felix Fietkau <[email protected]> (cherry picked from commit 96f134d) Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1132d1c commit e5c3ac8

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

drivers/net/wireless/mediatek/mt76/dma.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q,
234234

235235
rx_token = mt76_rx_token_consume(dev, (void *)skb, t,
236236
buf[0].addr);
237+
if (rx_token < 0)
238+
return -ENOMEM;
239+
237240
buf1 |= FIELD_PREP(MT_DMA_CTL_TOKEN, rx_token);
238241
ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len) |
239242
MT_DMA_CTL_TO_HOST;
@@ -602,7 +605,12 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q)
602605
qbuf.addr = addr + offset;
603606
qbuf.len = len - offset;
604607
qbuf.skip_unmap = false;
605-
mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t);
608+
if (mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t) < 0) {
609+
dma_unmap_single(dev->dma_dev, addr, len,
610+
DMA_FROM_DEVICE);
611+
skb_free_frag(buf);
612+
break;
613+
}
606614
frames++;
607615
}
608616

drivers/net/wireless/mediatek/mt76/mt7915/mmio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,13 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
653653

654654
desc->buf0 = cpu_to_le32(phy_addr);
655655
token = mt76_rx_token_consume(&dev->mt76, ptr, t, phy_addr);
656+
if (token < 0) {
657+
dma_unmap_single(dev->mt76.dma_dev, phy_addr,
658+
wed->wlan.rx_size, DMA_TO_DEVICE);
659+
skb_free_frag(ptr);
660+
goto unmap;
661+
}
662+
656663
desc->token |= cpu_to_le32(FIELD_PREP(MT_DMA_CTL_TOKEN,
657664
token));
658665
desc++;

drivers/net/wireless/mediatek/mt76/tx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,12 @@ int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
764764
spin_lock_bh(&dev->rx_token_lock);
765765
token = idr_alloc(&dev->rx_token, t, 0, dev->rx_token_size,
766766
GFP_ATOMIC);
767+
if (token >= 0) {
768+
t->ptr = ptr;
769+
t->dma_addr = phys;
770+
}
767771
spin_unlock_bh(&dev->rx_token_lock);
768772

769-
t->ptr = ptr;
770-
t->dma_addr = phys;
771-
772773
return token;
773774
}
774775
EXPORT_SYMBOL_GPL(mt76_rx_token_consume);

0 commit comments

Comments
 (0)