diff mbox series

mt76: usb: fix warning in mt76u_buf_free

Message ID bfd5659680fb3ef89554a48ff950d74dd88240dd.1550706341.git.lorenzo@kernel.org (mailing list archive)
State Accepted
Delegated to: Kalle Valo
Headers show
Series mt76: usb: fix warning in mt76u_buf_free | expand

Commit Message

Lorenzo Bianconi Feb. 20, 2019, 11:57 p.m. UTC
From: Lorenzo Bianconi <lorenzo@kernel.org>

Fix following static checker warning in mt76u_buf_free:
  drivers/net/wireless/mediatek/mt76/usb.c:372 mt76u_buf_free()
  warn: address of 'urb->sg[i]' is non-NULL

There is no need to check sg page pointer since urb->num_sgs
has been already validated in mt76u_fill_rx_sg

Fixes: cb83585e1121 ("mt76: usb: fix possible memory leak in mt76u_buf_free")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/usb.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Kalle Valo Feb. 21, 2019, 5:10 a.m. UTC | #1
lorenzo@kernel.org writes:

> From: Lorenzo Bianconi <lorenzo@kernel.org>
>
> Fix following static checker warning in mt76u_buf_free:
>   drivers/net/wireless/mediatek/mt76/usb.c:372 mt76u_buf_free()
>   warn: address of 'urb->sg[i]' is non-NULL
>
> There is no need to check sg page pointer since urb->num_sgs
> has been already validated in mt76u_fill_rx_sg
>
> Fixes: cb83585e1121 ("mt76: usb: fix possible memory leak in mt76u_buf_free")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

The merge window is really close, should I take this directly to
wireless-drivers-next?

BTW, Lorenzo please add your name to SMTP From line to make threading
cleaner:

From:   lorenzo@kernel.org
Lorenzo Bianconi Feb. 21, 2019, 7:15 a.m. UTC | #2
> lorenzo@kernel.org writes:
> 
> > From: Lorenzo Bianconi <lorenzo@kernel.org>
> >
> > Fix following static checker warning in mt76u_buf_free:
> >   drivers/net/wireless/mediatek/mt76/usb.c:372 mt76u_buf_free()
> >   warn: address of 'urb->sg[i]' is non-NULL
> >
> > There is no need to check sg page pointer since urb->num_sgs
> > has been already validated in mt76u_fill_rx_sg
> >
> > Fixes: cb83585e1121 ("mt76: usb: fix possible memory leak in mt76u_buf_free")
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> The merge window is really close, should I take this directly to
> wireless-drivers-next?

Hi Kalle,

I think this patch can go in Felix's tree for the moment since it just fixes the warning,
the intended behaviour is to run skb_free_frag()

Regards,
Lorenzo

> 
> BTW, Lorenzo please add your name to SMTP From line to make threading
> cleaner:
> 
> From:   lorenzo@kernel.org
> 
> -- 
> Kalle Valo
Felix Fietkau Feb. 26, 2019, 9:41 a.m. UTC | #3
On 2019-02-21 00:57, lorenzo@kernel.org wrote:
> From: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> Fix following static checker warning in mt76u_buf_free:
>   drivers/net/wireless/mediatek/mt76/usb.c:372 mt76u_buf_free()
>   warn: address of 'urb->sg[i]' is non-NULL
> 
> There is no need to check sg page pointer since urb->num_sgs
> has been already validated in mt76u_fill_rx_sg
> 
> Fixes: cb83585e1121 ("mt76: usb: fix possible memory leak in mt76u_buf_free")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied, thanks.

- Felix
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
index cbfddf2ebfeb..ac3da948d43a 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -364,16 +364,11 @@  mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf)
 void mt76u_buf_free(struct mt76u_buf *buf)
 {
 	struct urb *urb = buf->urb;
-	struct scatterlist *sg;
 	int i;
 
-	for (i = 0; i < urb->num_sgs; i++) {
-		sg = &urb->sg[i];
-		if (!sg)
-			continue;
+	for (i = 0; i < urb->num_sgs; i++)
+		skb_free_frag(sg_virt(&urb->sg[i]));
 
-		skb_free_frag(sg_virt(sg));
-	}
 	if (buf->buf)
 		skb_free_frag(buf->buf);