diff mbox series

[1/2] mt76: dma: do not build skb if reported len does not fit in buf_size

Message ID 0583d3f607ef493df9a2ff12bbe773174008027d.1543846816.git.lorenzo.bianconi@redhat.com (mailing list archive)
State Accepted
Delegated to: Kalle Valo
Headers show
Series add rx buffer recycle support to mt76x2e/mt76x0e drivers | expand

Commit Message

Lorenzo Bianconi Dec. 3, 2018, 2:34 p.m. UTC
Precompute data length in order to avoid to allocate the related
skb data structure if reported length does not fit in queue buf_size

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 drivers/net/wireless/mediatek/mt76/dma.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Lorenzo Bianconi Dec. 28, 2018, 1:34 p.m. UTC | #1
>
> Precompute data length in order to avoid to allocate the related
> skb data structure if reported length does not fit in queue buf_size
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
>  drivers/net/wireless/mediatek/mt76/dma.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
> index b7fd2e110663..1db163c40dcf 100644
> --- a/drivers/net/wireless/mediatek/mt76/dma.c
> +++ b/drivers/net/wireless/mediatek/mt76/dma.c
> @@ -417,10 +417,9 @@ mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data,
>  static int
>  mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
>  {
> +       int len, data_len, done = 0;
>         struct sk_buff *skb;
>         unsigned char *data;
> -       int len;
> -       int done = 0;
>         bool more;
>
>         while (done < budget) {
> @@ -430,7 +429,12 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
>                 if (!data)
>                         break;
>
> -               if (q->buf_size < len + q->buf_offset) {
> +               if (q->rx_head)
> +                       data_len = q->buf_size;
> +               else
> +                       data_len = SKB_WITH_OVERHEAD(q->buf_size);
> +
> +               if (data_len < len + q->buf_offset) {
>                         dev_kfree_skb(q->rx_head);
>                         q->rx_head = NULL;
>
> @@ -448,12 +452,7 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
>                         skb_free_frag(data);
>                         continue;
>                 }
> -
>                 skb_reserve(skb, q->buf_offset);
> -               if (skb->tail + len > skb->end) {
> -                       dev_kfree_skb(skb);
> -                       continue;
> -               }
>
>                 if (q == &dev->q_rx[MT_RXQ_MCU]) {
>                         u32 *rxfce = (u32 *) skb->cb;
> --
> 2.19.2
>

Hi Felix,

what about this patch?

Regards,
Lorenzo
Felix Fietkau Dec. 28, 2018, 3:16 p.m. UTC | #2
On 2018-12-03 15:34, Lorenzo Bianconi wrote:
> Precompute data length in order to avoid to allocate the related
> skb data structure if reported length does not fit in queue buf_size
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>

Applied, thanks.

- Felix
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
index b7fd2e110663..1db163c40dcf 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/dma.c
@@ -417,10 +417,9 @@  mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data,
 static int
 mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
 {
+	int len, data_len, done = 0;
 	struct sk_buff *skb;
 	unsigned char *data;
-	int len;
-	int done = 0;
 	bool more;
 
 	while (done < budget) {
@@ -430,7 +429,12 @@  mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
 		if (!data)
 			break;
 
-		if (q->buf_size < len + q->buf_offset) {
+		if (q->rx_head)
+			data_len = q->buf_size;
+		else
+			data_len = SKB_WITH_OVERHEAD(q->buf_size);
+
+		if (data_len < len + q->buf_offset) {
 			dev_kfree_skb(q->rx_head);
 			q->rx_head = NULL;
 
@@ -448,12 +452,7 @@  mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
 			skb_free_frag(data);
 			continue;
 		}
-
 		skb_reserve(skb, q->buf_offset);
-		if (skb->tail + len > skb->end) {
-			dev_kfree_skb(skb);
-			continue;
-		}
 
 		if (q == &dev->q_rx[MT_RXQ_MCU]) {
 			u32 *rxfce = (u32 *) skb->cb;