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. The following Rockchip fix uses the helper at the start of rkcanfd_stop() to wait for recovery before IRQ teardown, leaving echo cleanup to close_candev(). Signed-off-by: Cunhao Lu <1579567540@qq.com> --- Changes in v6: - Describe the helper's use by the following Rockchip fix. --- drivers/net/can/dev/dev.c | 4 +--- include/linux/can/dev.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c index a893a49a3381..39271a3ef0fa 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -537,9 +537,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 6d0710d6f571..1b08ee263b1f 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,22 @@ struct can_priv *safe_candev_priv(struct net_device *dev); int open_candev(struct net_device *dev); void close_candev(struct net_device *dev); + +/** + * close_candev_cancel_restart_sync() - cancel bus-off restart synchronously + * @dev: CAN network device + * + * Call before tearing down resources used by the restart callback. + * The driver must quiesce restart work producers before calling + * 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