Skip to content

Commit

Permalink
drivers: eth: gmac: fix race condition in packet reference counting
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
aurel32 authored and jukkar committed Jan 29, 2019
1 parent d678f30 commit 33dae59
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/ethernet/eth_sam_gmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,11 +1396,11 @@ static int eth_tx(struct device *dev, struct net_pkt *pkt)
/* Account for a sent frame */
ring_buf_put(&queue->tx_frames, POINTER_TO_UINT(pkt));

irq_unlock(key);

/* pkt is internally queued, so it requires to hold a reference */
net_pkt_ref(pkt);

irq_unlock(key);

/* Guarantee that the first fragment got its bit removed before starting
* sending packets to avoid packets getting stuck.
*/
Expand Down

0 comments on commit 33dae59

Please sign in to comment.