Skip to content

Commit a9daba1

Browse files
nbd168gregkh
authored andcommitted
mt76: fix tx skb error handling in mt76_dma_tx_queue_skb
[ Upstream commit ae064fc ] When running out of room in the tx queue after calling drv->tx_prepare_skb, the buffer list will already have been modified on MT7615 and newer drivers. This can leak a DMA mapping and will show up as swiotlb allocation failures on x86. Fix this by moving the queue length check further up. This is less accurate, since it can overestimate the needed room in the queue on MT7615 and newer, but the difference is small enough to not matter in practice. Signed-off-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/20210216135119.23809-1-nbd@nbd.name Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent efb12c0 commit a9daba1

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

  • drivers/net/wireless/mediatek/mt76

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
355355
};
356356
struct ieee80211_hw *hw;
357357
int len, n = 0, ret = -ENOMEM;
358-
struct mt76_queue_entry e;
359358
struct mt76_txwi_cache *t;
360359
struct sk_buff *iter;
361360
dma_addr_t addr;
@@ -397,6 +396,11 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
397396
}
398397
tx_info.nbuf = n;
399398

399+
if (q->queued + (tx_info.nbuf + 1) / 2 >= q->ndesc - 1) {
400+
ret = -ENOMEM;
401+
goto unmap;
402+
}
403+
400404
dma_sync_single_for_cpu(dev->dev, t->dma_addr, dev->drv->txwi_size,
401405
DMA_TO_DEVICE);
402406
ret = dev->drv->tx_prepare_skb(dev, txwi, qid, wcid, sta, &tx_info);
@@ -405,11 +409,6 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
405409
if (ret < 0)
406410
goto unmap;
407411

408-
if (q->queued + (tx_info.nbuf + 1) / 2 >= q->ndesc - 1) {
409-
ret = -ENOMEM;
410-
goto unmap;
411-
}
412-
413412
return mt76_dma_add_buf(dev, q, tx_info.buf, tx_info.nbuf,
414413
tx_info.info, tx_info.skb, t);
415414

@@ -425,9 +424,7 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
425424
dev->test.tx_done--;
426425
#endif
427426

428-
e.skb = tx_info.skb;
429-
e.txwi = t;
430-
dev->drv->tx_complete_skb(dev, &e);
427+
dev_kfree_skb(tx_info.skb);
431428
mt76_put_txwi(dev, t);
432429
return ret;
433430
}

0 commit comments

Comments
 (0)