Skip to content

Commit 33dae59

Browse files
aurel32jukkar
authored andcommitted
drivers: eth: gmac: fix race condition in packet reference counting
The SAM E70 GMAC ethernet driver reference a packet with net_pkt_ref() when queueing a packet, and unreference it with net_pkt_unref() in the ISR when it has been fully sent. The call to net_pkt_ref() is done just after re-enabling the interruptions, so there is however a small race condition that might cause the packet to be unreference before being referenced. This is only theoretical and has not been seen in practice. Fix that by moving the call to net_pkt_ref() just before re-enabling the interruptions. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
1 parent d678f30 commit 33dae59

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/ethernet/eth_sam_gmac.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1396,11 +1396,11 @@ static int eth_tx(struct device *dev, struct net_pkt *pkt)
13961396
/* Account for a sent frame */
13971397
ring_buf_put(&queue->tx_frames, POINTER_TO_UINT(pkt));
13981398

1399-
irq_unlock(key);
1400-
14011399
/* pkt is internally queued, so it requires to hold a reference */
14021400
net_pkt_ref(pkt);
14031401

1402+
irq_unlock(key);
1403+
14041404
/* Guarantee that the first fragment got its bit removed before starting
14051405
* sending packets to avoid packets getting stuck.
14061406
*/

0 commit comments

Comments
 (0)