From 6701d91c5033a3804a3bb5d49a8f9f2212b901b4 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 5 Jul 2023 14:30:54 +0100 Subject: [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 --- src/net/netdevice.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 07961bf..9151782 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -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 ); -- cgit v1.1