Skip to contentSkip to conversation

mt76: usb: do not build the skb if reported len does not fit in buf_size

PATCH Applied Lorenzo Bianconi 2 participants 2 messages Dec 1, 2018 – Dec 28, 2018 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/1 mt76: usb: do not build the skb if reported len does not fit in buf_size

In reply to a message not in the archive

Precompute data length in order to avoid to allocate the related skb data structure if reported length does not fit in queue buf_size

---
 drivers/net/wireless/mediatek/mt76/usb.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +4 -6
index b061263453d4..14ff06c5764e 100644
@@ -407,17 +407,15 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb)
 	if (len < 0)
 		return 0;
 
+	data_len = min_t(int, len, urb->sg[0].length - MT_DMA_HDR_LEN);
+	if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size))
+		return 0;
+
 	skb = build_skb(data, q->buf_size);
 	if (!skb)
 		return 0;
 
-	data_len = min_t(int, len, urb->sg[0].length - MT_DMA_HDR_LEN);
 	skb_reserve(skb, MT_DMA_HDR_LEN);
-	if (skb->tail + data_len > skb->end) {
-		dev_kfree_skb(skb);
-		return 1;
-	}
-
 	__skb_put(skb, data_len);
 	len -= data_len;
 
Signature · 1 line
2.19.2
maintainer Applied
#2 lore raw
Quoted 4 lines · Lorenzo Bianconi

Precompute data length in order to avoid to allocate the related skb data structure if reported length does not fit in queue buf_size

Applied, thanks.

- Felix