Skip to content

Commit 5440428

Browse files
can: gs_usb: gs_can_open(): fix race dev->can.state condition
The dev->can.state is set to CAN_STATE_ERROR_ACTIVE, after the device has been started. On busy networks the CAN controller might receive CAN frame between and go into an error state before the dev->can.state is assigned. Assign dev->can.state before starting the controller to close the race window. Fixes: d08e973 ("can: gs_usb: Added support for the GS_USB CAN devices") Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent a09721d commit 5440428

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/can/usb/gs_usb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ static int gs_can_open(struct net_device *netdev)
824824
flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
825825

826826
/* finally start device */
827+
dev->can.state = CAN_STATE_ERROR_ACTIVE;
827828
dm->mode = cpu_to_le32(GS_CAN_MODE_START);
828829
dm->flags = cpu_to_le32(flags);
829830
rc = usb_control_msg(interface_to_usbdev(dev->iface),
@@ -835,13 +836,12 @@ static int gs_can_open(struct net_device *netdev)
835836
if (rc < 0) {
836837
netdev_err(netdev, "Couldn't start device (err=%d)\n", rc);
837838
kfree(dm);
839+
dev->can.state = CAN_STATE_STOPPED;
838840
return rc;
839841
}
840842

841843
kfree(dm);
842844

843-
dev->can.state = CAN_STATE_ERROR_ACTIVE;
844-
845845
parent->active_channels++;
846846
if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
847847
netif_start_queue(netdev);

0 commit comments

Comments
 (0)