Skip to contentSkip to conversation

wifi: ath9k: unmap DMA and free skb for stale TX buffers on queue drain

PATCH In review Rosen Penev 2 participants 2 messages Sep 4 – Sep 11 Qualcomm Atheros ATH9K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: ath9k: unmap DMA and free skb for stale TX buffers on queue drain

When draining a TX queue (e.g. on device removal or reset), stale ath_buf descriptors were returned directly to the free pool via ath_tx_return_buffer without unmapping their DMA buffers or freeing their associated skbs. This leaks both DMA API resources and socket buffer memory.

Unmap the DMA buffer and free the skb before returning the buffer to the pool.

Assisted-by opencode:big-pickle
---
 drivers/net/wireless/ath/ath9k/xmit.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/xmit.c +10 -1
index 89d8b3178784..89930eaf1fd3 100644
@@ -1884,8 +1884,17 @@ static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq,
 		bf = list_first_entry(list, struct ath_buf, list);
 
 		if (bf->bf_state.stale) {
-			list_del(&bf->list);
+			struct sk_buff *skb = bf->bf_mpdu;
 
+			list_del(&bf->list);
+			if (bf->bf_buf_addr) {
+				dma_unmap_single(sc->dev, bf->bf_buf_addr,
+						 skb ? skb->len : 0,
+						 DMA_TO_DEVICE);
+				bf->bf_buf_addr = 0;
+			}
+			bf->bf_mpdu = NULL;
+			dev_kfree_skb_any(skb);
 			ath_tx_return_buffer(sc, bf);
 			continue;
 		}
Signature · 1 line
2.55.0
#1 lore raw
Quoted 21 lines · Rosen Penev

When draining a TX queue (e.g. on device removal or reset), stale ath_buf descriptors were returned directly to the free pool via ath_tx_return_buffer without unmapping their DMA buffers or freeing their associated skbs. This leaks both DMA API resources and socket buffer memory.

Unmap the DMA buffer and free the skb before returning the buffer to the pool.

Assisted-by opencode:big-pickle
---
 drivers/net/wireless/ath/ath9k/xmit.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/xmit.c +0 -0
index 89d8b3178784..89930eaf1fd3 100644
@@ -1884,8 +1884,17 @@ static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq,
 		bf = list_first_entry(list, struct ath_buf, list);

drivers/net/wireless/ath/ath9k/xmit.c static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq, · line 1893

Quoted 10 lines
drivers/net/wireless/ath/ath9k/xmit.c +6 -1
 
 		if (bf->bf_state.stale) {
-			list_del(&bf->list);
+			struct sk_buff *skb = bf->bf_mpdu;
 
+			list_del(&bf->list);
+			if (bf->bf_buf_addr) {
+				dma_unmap_single(sc->dev, bf->bf_buf_addr,
+						 skb ? skb->len : 0,
+						 DMA_TO_DEVICE);

A zero-length unmap? That seems completely non-sensical. Is there even a bug here? AFAICT, the only place where a buf is set as stale, the aggregate subsequently goes through ath_tx_complete_buf(), which does the unmapping.

Did you test this? Unless you can demonstrate a real bug here, I'm just going to assume this is all LLM garbage output.

-Toke