]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[netdevice] Stop link block timer when device is closed
authorMichael Brown <mcb30@ipxe.org>
Wed, 5 Jul 2023 13:30:54 +0000 (14:30 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 5 Jul 2023 13:30:54 +0000 (14:30 +0100)
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>
src/net/netdevice.c

index 07961bf2033897d9ae9596b2b5e097f3840ab59d..91517821899561140fc7308421b8e90521fa8496 100644 (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 );