[netdevice] Stop link block timer when device is closed

A running link block timer holds a reference to the network device and
will prevent it from being freed until the timer expires.  It is
impossible for free_netdev() to be called while the timer is still
running: the call to stop_timer() therein is therefore a no-op.

Stop the link block timer when the device is closed, to allow a
link-blocked device to be freed immediately upon unregistration of the
device.  (Since link block state is updated in response to received
packets, the state is effectively undefined for a closed device: there
is therefore no reason to leave the timer running.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/990/head
Michael Brown 2023-07-05 14:30:54 +01:00
parent b5b60ea33d
commit 6701d91c50
1 changed files with 4 additions and 1 deletions

View File

@ -656,7 +656,7 @@ static void free_netdev ( struct refcnt *refcnt ) {
struct net_device *netdev =
container_of ( refcnt, struct net_device, refcnt );
stop_timer ( &netdev->link_block );
assert ( ! timer_running ( &netdev->link_block ) );
netdev_tx_flush ( netdev );
netdev_rx_flush ( netdev );
clear_settings ( netdev_settings ( netdev ) );
@ -879,6 +879,9 @@ void netdev_close ( struct net_device *netdev ) {
/* Close the device */
netdev->op->close ( netdev );
/* Stop link block timer */
stop_timer ( &netdev->link_block );
/* Flush TX and RX queues */
netdev_tx_flush ( netdev );
netdev_rx_flush ( netdev );