can: gs_usb: fix hardware timestamp state for mixed channels
Subsystems (2)
PATCH 1/1 can: gs_usb: fix hardware timestamp state for mixed channels
The hardware timestamp state is shared by struct gs_usb, but gs_can_open() and gs_can_close() tie its initialization and teardown to active_channels and to the feature bits of the channel being opened or closed.
This is wrong for mixed-channel devices in both directions. If a non-timestamp channel opens first, a later timestamp-capable channel does not initialize the shared cyclecounter/timecounter because active_channels is already non-zero. Timestamp RX then calls timecounter_cyc2time() with parent->tc.cc unset.
Conversely, if a timestamp-capable channel opens first and starts the shared delayed work, then closes while a non-timestamp channel remains active, disconnect may close the non-timestamp channel last. The old teardown check skips gs_usb_timestamp_stop() in that case and frees struct gs_usb while the delayed work timer is still queued.
Track whether the shared timestamp work has been started in struct gs_usb. Start it whenever opening a timestamp-capable channel and the shared state is not started yet, and stop it when the last channel closes regardless of that channel's feature bits. Initialize the delayed work and lock once during probe.
--- drivers/net/can/usb/gs_usb.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/net/can/usb/gs_usb.c +20 -10
@@ -337,6 +337,7 @@ struct gs_usb {unsigned int hf_size_rx;u8 active_channels; +bool timestamp_started;u8 channel_cnt;unsigned int pipe_in;
@@ -480,19 +481,23 @@ static void gs_usb_timestamp_init(struct gs_usb *parent) cc->shift =32 -bits_per (NSEC_PER_SEC /GS_USB_TIMESTAMP_TIMER_HZ ); cc->mult =clocksource_hz2mult (GS_USB_TIMESTAMP_TIMER_HZ , cc->shift); -spin_lock_init (&parent->tc_lock);spin_lock_bh (&parent->tc_lock);timecounter_init (&parent->tc, &parent->cc,ktime_get_real_ns ());spin_unlock_bh (&parent->tc_lock); -INIT_DELAYED_WORK (&parent->timestamp, gs_usb_timestamp_work);schedule_delayed_work (&parent->timestamp,GS_USB_TIMESTAMP_WORK_DELAY_SEC *HZ ); + + parent->timestamp_started = true; }static void gs_usb_timestamp_stop (struct gs_usb *parent) { +if (!parent->timestamp_started) +return ; +cancel_delayed_work_sync (&parent->timestamp); + parent->timestamp_started = false; }static void gs_update_state (struct gs_can *dev,struct can_frame *cf)
@@ -959,6 +964,7 @@ static int gs_can_open(struct net_device *netdev)struct urb *urb =NULL ;u32 ctrlmode;u32 flags =0 ; +bool timestamp_started = false;int rc, i; rc =open_candev (netdev);
@@ -980,10 +986,13 @@ static int gs_can_open(struct net_device *netdev)can_rx_offload_enable (&dev->offload); -if (!parent->active_channels) { -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) -gs_usb_timestamp_init (parent); +if ((dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) && + !parent->timestamp_started) { +gs_usb_timestamp_init (parent); + timestamp_started = true; + } +if (!parent->active_channels) {for (i =0 ; i <GS_MAX_RX_URBS ; i++) {u8 *buf;
@@ -1094,11 +1103,11 @@ static int gs_can_open(struct net_device *netdev) out_usb_free_urb:usb_free_urb (urb); out_usb_kill_anchored_urbs: +if (timestamp_started) +gs_usb_timestamp_stop (parent); +if (!parent->active_channels) {usb_kill_anchored_urbs (&parent->rx_submitted); - -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) -gs_usb_timestamp_stop (parent); }can_rx_offload_disable (&dev->offload);
@@ -1155,8 +1164,7 @@ static int gs_can_close(struct net_device *netdev)if (!parent->active_channels) {usb_kill_anchored_urbs (&parent->rx_submitted); -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) -gs_usb_timestamp_stop (parent); +gs_usb_timestamp_stop (parent); }/* Stop sending URBs */
@@ -1577,6 +1585,8 @@ static int gs_usb_probe(struct usb_interface *intf, parent->channel_cnt = icount;init_usb_anchor (&parent->rx_submitted); +spin_lock_init (&parent->tc_lock); +INIT_DELAYED_WORK (&parent->timestamp, gs_usb_timestamp_work);usb_set_intfdata (intf, parent); parent->udev = udev;
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Potential deadlock due to using spin_lock_bh for tc_lock while it is acquired in an URB completion handler.
- [High] A malicious or buggy USB device can cause a kernel panic by sending an RX URB for a channel that hasn't been fully initialized.
- [High] A malicious USB device can cause a kernel panic by sending an RX URB for a timestamp-capable channel before the timecounter is initialized. --
--- Patch [1]: [PATCH can] can: gs_usb: fix hardware timestamp state for mixed channels --- commit d94a7b828312e3ba70b37ab83b64617437b2e0cb
Author: Shuangpeng Bai <[email protected]>
can: gs_usb: fix hardware timestamp state for mixed channels
The hardware timestamp state is shared by struct gs_usb, but gs_can_open() and gs_can_close() tie its initialization and teardown to active_channels and to the feature bits of the channel being opened or closed.
This is wrong for mixed-channel devices in both directions. If a non-timestamp channel opens first, a later timestamp-capable channel does not initialize the shared cyclecounter/timecounter because active_channels is already non-zero. Timestamp RX then calls timecounter_cyc2time() with parent->tc.cc unset.
Quoted 4 lines
drivers/net/can/usb/gs_usb.c +0
-0
[ ... ]
drivers/net/can/usb/gs_usb.c static void gs_usb_timestamp_init(struct gs_usb *parent) · line 484
Quoted 6 lines
drivers/net/can/usb/gs_usb.c +0
-1@@ -480,19 +481,23 @@ static void gs_usb_timestamp_init(struct gs_usb *parent) cc->shift =32 -bits_per (NSEC_PER_SEC /GS_USB_TIMESTAMP_TIMER_HZ ); cc->mult =clocksource_hz2mult (GS_USB_TIMESTAMP_TIMER_HZ , cc->shift); -spin_lock_init (&parent->tc_lock);spin_lock_bh (&parent->tc_lock);
[Severity: High]
This is a pre-existing issue, but is it possible for a deadlock to occur here?
The lock tc_lock is acquired using spin_lock_bh() in process context (gs_usb_timestamp_work). If a USB RX URB completion (gs_usb_receive_bulk_callback) fires in hardirq context, it interrupts the process context.
The URB callback then calls gs_usb_skb_set_timestamp(), which also tries to acquire tc_lock using spin_lock_bh():
gs_usb_skb_set_timestamp() {
...
spin_lock_bh(&parent->tc_lock);
...
}Would this spin forever since the lock is already held by the interrupted thread?
Quoted 3 lines
drivers/net/can/usb/gs_usb.c +0
-0timecounter_init (&parent->tc, &parent->cc,ktime_get_real_ns ());spin_unlock_bh (&parent->tc_lock);
[ ... ]
drivers/net/can/usb/gs_usb.c static int gs_can_open(struct net_device *netdev) · line 993
Quoted 12 lines
drivers/net/can/usb/gs_usb.c +5
-3@@ -980,10 +986,13 @@ static int gs_can_open(struct net_device *netdev)can_rx_offload_enable (&dev->offload); -if (!parent->active_channels) { -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) -gs_usb_timestamp_init (parent); +if ((dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) && + !parent->timestamp_started) { +gs_usb_timestamp_init (parent); + timestamp_started = true; + }
[Severity: High]
This is a pre-existing issue, but could a malicious USB device cause a kernel panic by sending an RX URB before the timecounter is initialized?
When opening a timestamp-capable channel while a non-timestamp channel is already open and submitting RX URBs, the network stack sets __LINK_STATE_START on the new channel before calling gs_can_open(). This makes netif_running() return true immediately.
During the race window before gs_can_open() initializes the timestamp state here, an RX frame for the new channel could be processed:
gs_usb_skb_set_timestamp() {
...
ns = timecounter_cyc2time(&parent->tc, timestamp);
...
}Since parent->tc.cc is still NULL, would this dereference a NULL pointer?
[ ... ]
drivers/net/can/usb/gs_usb.c static int gs_usb_probe(struct usb_interface *intf, · line 1585
Quoted 2 lines
drivers/net/can/usb/gs_usb.c +0
-0@@ -1577,6 +1585,8 @@ static int gs_usb_probe(struct usb_interface *intf, parent->channel_cnt = icount;
[Severity: High]
This is a pre-existing issue, but could a malicious USB device trigger a NULL pointer dereference by sending an RX URB for a channel that hasn't been fully initialized?
The count parent->channel_cnt is set to its maximum here, before the underlying objects are fully allocated in the loop that follows.
If userspace brings up the first channel while the loop is still initializing the remaining channels, RX URBs are submitted. A device could immediately send an RX URB with a channel index that hasn't been allocated yet.
The callback gs_usb_receive_bulk_callback() checks the channel:
if (hf->channel >= parent->channel_cnt)
...This check would pass, but the uninitialized array element is accessed:
dev = parent->canch[hf->channel];
netdev = dev->netdev;Would this cause a panic when dereferencing dev?
Quoted 7 lines
drivers/net/can/usb/gs_usb.c +2
-0init_usb_anchor (&parent->rx_submitted); +spin_lock_init (&parent->tc_lock); +INIT_DELAYED_WORK (&parent->timestamp, gs_usb_timestamp_work);usb_set_intfdata (intf, parent); parent->udev = udev;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 16 lines · Shuangpeng Bai
The hardware timestamp state is shared by struct
gs_usb, butgs_can_open()andgs_can_close()tie its initialization and teardown toactive_channelsand to the feature bits of the channel being opened or closed.This is wrong for mixed-channel devices in both directions. If a non-timestamp channel opens first, a later timestamp-capable channel does not initialize the shared cyclecounter/timecounter because
active_channelsis already non-zero. Timestamp RX then callstimecounter_cyc2time()withparent->tc.ccunset.Conversely, if a timestamp-capable channel opens first and starts the shared delayed work, then closes while a non-timestamp channel remains active, disconnect may close the non-timestamp channel last. The old teardown check skips
gs_usb_timestamp_stop()in that case and frees structgs_usbwhile the delayed work timer is still queued.
Quoted 5 lines
Track whether the shared timestamp work has been started in struct
gs_usb. Start it whenever opening a timestamp-capable channel and the shared state is not started yet, and stop it when the last channel closes regardless of that channel's feature bits. Initialize the delayed work and lock once during probe.
With this code, the gs_usb_timestamp_work will run even if there are no more timestamp-capable channels are open (after multiple open/close calls). I think it would be better to implement counter of timestamp-capable channels and rework timestamp code to use this counter as an indicator of when to start/stop worker.
Quoted 105 lines
Fixes 45dfa45f52e6 ("can: gs_usb: add RX and TX hardware timestamp support")Signed-off-by Shuangpeng Bai <[email protected]>--- drivers/net/can/usb/gs_usb.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)drivers/net/can/usb/gs_usb.c +20
-10@@ -337,6 +337,7 @@ struct gs_usb {unsigned int hf_size_rx;u8 active_channels; +bool timestamp_started;u8 channel_cnt;unsigned int pipe_in;@@ -480,19 +481,23 @@ static void gs_usb_timestamp_init(struct gs_usb *parent) cc->shift =32 -bits_per (NSEC_PER_SEC /GS_USB_TIMESTAMP_TIMER_HZ ); cc->mult =clocksource_hz2mult (GS_USB_TIMESTAMP_TIMER_HZ , cc->shift); -spin_lock_init (&parent->tc_lock);spin_lock_bh (&parent->tc_lock);timecounter_init (&parent->tc, &parent->cc,ktime_get_real_ns ());spin_unlock_bh (&parent->tc_lock); -INIT_DELAYED_WORK (&parent->timestamp, gs_usb_timestamp_work);schedule_delayed_work (&parent->timestamp,GS_USB_TIMESTAMP_WORK_DELAY_SEC *HZ ); + + parent->timestamp_started = true; }static void gs_usb_timestamp_stop (struct gs_usb *parent) { +if (!parent->timestamp_started) +return ; +cancel_delayed_work_sync (&parent->timestamp); + parent->timestamp_started = false; }static void gs_update_state (struct gs_can *dev,struct can_frame *cf)@@ -959,6 +964,7 @@ static int gs_can_open(struct net_device *netdev)struct urb *urb =NULL ;u32 ctrlmode;u32 flags =0 ; +bool timestamp_started = false;int rc, i; rc =open_candev (netdev);@@ -980,10 +986,13 @@ static int gs_can_open(struct net_device *netdev)can_rx_offload_enable (&dev->offload); -if (!parent->active_channels) { -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) -gs_usb_timestamp_init (parent); +if ((dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) && + !parent->timestamp_started) { +gs_usb_timestamp_init (parent); + timestamp_started = true; + } +if (!parent->active_channels) {for (i =0 ; i <GS_MAX_RX_URBS ; i++) {u8 *buf;@@ -1094,11 +1103,11 @@ static int gs_can_open(struct net_device *netdev) out_usb_free_urb:usb_free_urb (urb); out_usb_kill_anchored_urbs: +if (timestamp_started) +gs_usb_timestamp_stop (parent); +if (!parent->active_channels) {usb_kill_anchored_urbs (&parent->rx_submitted); - -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) -gs_usb_timestamp_stop (parent); }can_rx_offload_disable (&dev->offload);@@ -1155,8 +1164,7 @@ static int gs_can_close(struct net_device *netdev)if (!parent->active_channels) {usb_kill_anchored_urbs (&parent->rx_submitted); -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) -gs_usb_timestamp_stop (parent); +gs_usb_timestamp_stop (parent); }/* Stop sending URBs */ @@ -1577,6 +1585,8 @@ static int gs_usb_probe(struct usb_interface *intf, parent->channel_cnt = icount;init_usb_anchor (&parent->rx_submitted); +spin_lock_init (&parent->tc_lock); +INIT_DELAYED_WORK (&parent->timestamp, gs_usb_timestamp_work);usb_set_intfdata (intf, parent); parent->udev = udev;
PATCH v2 1/1 can: gs_usb: fix hardware timestamp state for mixed channels
In reply to Shuangpeng BaiThe hardware timestamp state is shared by struct gs_usb, but gs_can_open() and gs_can_close() tie its initialization and teardown to active_channels and to the feature bits of the channel being opened or closed.
This is wrong for mixed-channel devices in both directions. If a non-timestamp channel opens first, a later timestamp-capable channel does not initialize the shared cyclecounter/timecounter because active_channels is already non-zero. Timestamp RX then calls timecounter_cyc2time() with parent->tc.cc unset.
Conversely, if a timestamp-capable channel opens first and starts the shared delayed work, then closes while a non-timestamp channel remains active, disconnect may close the non-timestamp channel last. The old teardown check skips gs_usb_timestamp_stop() in that case and frees struct gs_usb while the delayed work timer is still queued.
Count the number of active timestamp-capable channels. Start the shared timestamp worker when the first such channel opens, stop it when the last such channel closes, and unwind the count if open fails.
---
Changes in v2:
- Count active timestamp-capable channels instead of tracking only whether the shared timestamp worker has been started.
- Stop the shared timestamp worker when the last timestamp-capable channel closes, even if non-timestamp channels remain open.
- Unwind the timestamp-capable channel count on gs_can_open() failures.
drivers/net/can/usb/gs_usb.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/net/can/usb/gs_usb.c +18 -10
@@ -337,6 +337,7 @@ struct gs_usb {unsigned int hf_size_rx;u8 active_channels; +u8 active_timestamp_channels;u8 channel_cnt;unsigned int pipe_in;
@@ -980,10 +981,13 @@ static int gs_can_open(struct net_device *netdev)can_rx_offload_enable (&dev->offload); -if (!parent->active_channels) { -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) +if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) { +if (!parent->active_timestamp_channels)gs_usb_timestamp_init (parent); + parent->active_timestamp_channels++; + } +if (!parent->active_channels) {for (i =0 ; i <GS_MAX_RX_URBS ; i++) {u8 *buf;
@@ -1094,13 +1098,15 @@ static int gs_can_open(struct net_device *netdev) out_usb_free_urb:usb_free_urb (urb); out_usb_kill_anchored_urbs: -if (!parent->active_channels) { -usb_kill_anchored_urbs (&parent->rx_submitted); - -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) +if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) { + parent->active_timestamp_channels--; +if (!parent->active_timestamp_channels)gs_usb_timestamp_stop (parent); } +if (!parent->active_channels) +usb_kill_anchored_urbs (&parent->rx_submitted); +can_rx_offload_disable (&dev->offload);close_candev (netdev);
@@ -1152,13 +1158,15 @@ static int gs_can_close(struct net_device *netdev)/* Stop polling */ parent->active_channels--; -if (!parent->active_channels) { -usb_kill_anchored_urbs (&parent->rx_submitted); - -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) +if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) { + parent->active_timestamp_channels--; +if (!parent->active_timestamp_channels)gs_usb_timestamp_stop (parent); } +if (!parent->active_channels) +usb_kill_anchored_urbs (&parent->rx_submitted); +/* Stop sending URBs */ usb_kill_anchored_urbs (&dev->tx_submitted);atomic_set (&dev->active_tx_urbs,0 );
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Data race and lock corruption due to unprotected initialization of shared timestamp lock --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Data race and lock corruption due to unprotected initialization of shared timestamp lock --
--- Patch [1]: [PATCH can v2] can: gs_usb: fix hardware timestamp state for mixed channels --- commit 5294b98eba495191f8e49a8e183658cbb1702465
Author: Shuangpeng Bai <[email protected]>
can: gs_usb: fix hardware timestamp state for mixed channels
This patch decouples the hardware timestamp state from active_channels. It tracks timestamp-capable channels separately to fix initialization for mixed-channel devices.
Quoted 4 lines
drivers/net/can/usb/gs_usb.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/can/usb/gs_usb.c +0
-1@@ -980,10 +981,13 @@ static int gs_can_open(struct net_device *netdev)can_rx_offload_enable (&dev->offload); -if (!parent->active_channels) {
drivers/net/can/usb/gs_usb.c static int gs_can_open(struct net_device *netdev) · line 992
Quoted 10 lines
drivers/net/can/usb/gs_usb.c +5
-1-if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) +if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) { +if (!parent->active_timestamp_channels)gs_usb_timestamp_init (parent); + parent->active_timestamp_channels++; + } +if (!parent->active_channels) {for (i =0 ; i <GS_MAX_RX_URBS ; i++) {u8 *buf;
[Severity: High]
Can this corrupt the tc_lock spinlock if an RX callback executes concurrently?
Since gs_usb_timestamp_init() is now called independently of !parent->active_channels, it can execute while RX URBs are already polling (if a non-timestamp channel was opened first).
gs_usb_timestamp_init() re-initializes the lock and timecounter:
spin_lock_init(&parent->tc_lock);
spin_lock_bh(&parent->tc_lock);
timecounter_init(&parent->tc, &parent->cc, ktime_get_real_ns());If a USB device injects an RX frame during this window, the active RX URB completion handler (gs_usb_receive_bulk_callback) can process it. Because __dev_open() sets __LINK_STATE_START before calling ndo_open(), the netif_running() check in the callback will pass, and gs_usb_skb_set_timestamp() could attempt to acquire parent->tc_lock at the same time it is being re-initialized.
Is there a way to safely initialize this lock before URBs are active, or initialize it only once during device probe?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 16 lines · Shuangpeng Bai
The hardware timestamp state is shared by struct
gs_usb, butgs_can_open()andgs_can_close()tie its initialization and teardown toactive_channelsand to the feature bits of the channel being opened or closed.This is wrong for mixed-channel devices in both directions. If a non-timestamp channel opens first, a later timestamp-capable channel does not initialize the shared cyclecounter/timecounter because
active_channelsis already non-zero. Timestamp RX then callstimecounter_cyc2time()withparent->tc.ccunset.Conversely, if a timestamp-capable channel opens first and starts the shared delayed work, then closes while a non-timestamp channel remains active, disconnect may close the non-timestamp channel last. The old teardown check skips
gs_usb_timestamp_stop()in that case and frees structgs_usbwhile the delayed work timer is still queued.
Quoted 7 lines
Count the number of active timestamp-capable channels. Start the shared timestamp worker when the first such channel opens, stop it when the last such channel closes, and unwind the count if open fails.
Fixes 45dfa45f52e6 ("can: gs_usb: add RX and TX hardware timestamp support")Suggested-by Vadim Fedorenko <[email protected]>
no need for this tag, I didn't suggest the idea
Quoted 25 lines
Signed-off-by Shuangpeng Bai <[email protected]>---
Changes in v2:
- Count active timestamp-capable channels instead of tracking only whether the shared timestamp worker has been started.
- Stop the shared timestamp worker when the last timestamp-capable channel closes, even if non-timestamp channels remain open.
- Unwind the timestamp-capable channel count ongs_can_open()failures.drivers/net/can/usb/gs_usb.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-)drivers/net/can/usb/gs_usb.c +1
-0@@ -337,6 +337,7 @@ struct gs_usb {unsigned int hf_size_rx;u8 active_channels; +u8 active_timestamp_channels;u8 channel_cnt;unsigned int pipe_in;
drivers/net/can/usb/gs_usb.c static int gs_can_open(struct net_device *netdev) · line 987
Quoted 9 lines
drivers/net/can/usb/gs_usb.c +3
-2@@ -980,10 +981,13 @@ static int gs_can_open(struct net_device *netdev)can_rx_offload_enable (&dev->offload); -if (!parent->active_channels) { -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) +if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) { +if (!parent->active_timestamp_channels)gs_usb_timestamp_init (parent); + parent->active_timestamp_channels++;
I think it would be better to move active_timestamp_channels management into gs_usb_timestamp_init()/gs_usb_timestamp_stop() - it will simplify code in main functions.
Please, start new thread for each version of your patch.
Quoted 46 lines
drivers/net/can/usb/gs_usb.c +14
-8+ } +if (!parent->active_channels) {for (i =0 ; i <GS_MAX_RX_URBS ; i++) {u8 *buf;@@ -1094,13 +1098,15 @@ static int gs_can_open(struct net_device *netdev) out_usb_free_urb:usb_free_urb (urb); out_usb_kill_anchored_urbs: -if (!parent->active_channels) { -usb_kill_anchored_urbs (&parent->rx_submitted); - -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) +if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) { + parent->active_timestamp_channels--; +if (!parent->active_timestamp_channels)gs_usb_timestamp_stop (parent); } +if (!parent->active_channels) +usb_kill_anchored_urbs (&parent->rx_submitted); +can_rx_offload_disable (&dev->offload);close_candev (netdev);@@ -1152,13 +1158,15 @@ static int gs_can_close(struct net_device *netdev)/* Stop polling */ parent->active_channels--; -if (!parent->active_channels) { -usb_kill_anchored_urbs (&parent->rx_submitted); - -if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) +if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) { + parent->active_timestamp_channels--; +if (!parent->active_timestamp_channels)gs_usb_timestamp_stop (parent); } +if (!parent->active_channels) +usb_kill_anchored_urbs (&parent->rx_submitted); +/* Stop sending URBs */ usb_kill_anchored_urbs (&dev->tx_submitted);atomic_set (&dev->active_tx_urbs,0 );