Skip to content

Commit b22170a

Browse files
Morduan Zanggregkh
authored andcommitted
net: usb: rtl8150: free skb on usb_submit_urb() failure in xmit
[ Upstream commit adbe2cd ] When rtl8150_start_xmit() fails to submit the tx URB, the URB is never handed to the USB core and write_bulk_callback() will not run. The driver returns NETDEV_TX_OK, which tells the networking stack that the skb has been consumed, but nothing actually frees the skb on this error path: dev->tx_skb = skb; ... if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) { ... /* no kfree_skb here */ } return NETDEV_TX_OK; This leaks the skb on every submit failure and also leaves dev->tx_skb pointing at memory that the driver itself may later free, which is fragile. Free the skb with dev_kfree_skb_any() in the error path and clear dev->tx_skb so no stale pointer is left behind. Fixes: 1da177e ("Linux-2.6.12-rc2") Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Morduan Zang <zhangdandan@uniontech.com> Link: https://patch.msgid.link/E7D3E1C013C5A859+20260424015517.9574-1-zhangdandan@uniontech.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 30cf982 commit b22170a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

drivers/net/usb/rtl8150.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,13 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,
712712
netdev->stats.tx_errors++;
713713
netif_start_queue(netdev);
714714
}
715+
/*
716+
* The URB was not submitted, so write_bulk_callback() will
717+
* never run to free dev->tx_skb. Drop the skb here and
718+
* clear tx_skb to avoid leaving a stale pointer.
719+
*/
720+
dev->tx_skb = NULL;
721+
dev_kfree_skb_any(skb);
715722
} else {
716723
netdev->stats.tx_packets++;
717724
netdev->stats.tx_bytes += skb_len;

0 commit comments

Comments
 (0)