From: Cunhao Lu <1579567540@qq.com> Drivers may need to wait for bus-off recovery before tearing down the IRQ and hardware resources used by their restart callback. Calling close_candev() at that point also flushes echo skbs, which belongs after the driver has quiesced the users of those buffers. Add close_candev_cancel_restart_sync() in linux/can/dev.h so drivers can cancel the core restart work separately, without accessing can_priv's work item directly. The helper only cancels restart work; callers must still stop its producers and call close_candev() for the final cleanup. Use the helper in close_candev(), preserving its existing cancellation and echo cleanup order. Cc: stable@vger.kernel.org Signed-off-by: Cunhao Lu <1579567540@qq.com> --- drivers/net/can/dev/dev.c | 4 +--- include/linux/can/dev.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c index 92492c503446e..52e8c4854ae0d 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -534,9 +534,7 @@ EXPORT_SYMBOL_GPL(of_can_transceiver); */ void close_candev(struct net_device *dev) { - struct can_priv *priv = netdev_priv(dev); - - cancel_delayed_work_sync(&priv->restart_work); + close_candev_cancel_restart_sync(dev); can_flush_echo_skb(dev); } EXPORT_SYMBOL_GPL(close_candev); diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 6d0710d6f571d..a277d12332f15 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -22,6 +22,7 @@ #include #include #include +#include /* * CAN mode @@ -115,6 +116,17 @@ struct can_priv *safe_candev_priv(struct net_device *dev); int open_candev(struct net_device *dev); void close_candev(struct net_device *dev); + +/* Cancel bus-off restart before tearing down resources used by the restart + * callback. The driver must still call close_candev() for the final cleanup. + */ +static inline void close_candev_cancel_restart_sync(struct net_device *dev) +{ + struct can_priv *priv = netdev_priv(dev); + + cancel_delayed_work_sync(&priv->restart_work); +} + void can_set_default_mtu(struct net_device *dev); void can_set_cap_info(struct net_device *dev); int __must_check can_set_static_ctrlmode(struct net_device *dev, -- 2.34.1