Skip to content

Commit c6d9396

Browse files
marckleinebuddegregkh
authored andcommitted
can: gs_usb: gs_can_open(): fix race dev->can.state condition
[ Upstream commit 5440428 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e1676ad commit c6d9396

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
@@ -680,6 +680,7 @@ static int gs_can_open(struct net_device *netdev)
680680
flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
681681

682682
/* finally start device */
683+
dev->can.state = CAN_STATE_ERROR_ACTIVE;
683684
dm->mode = cpu_to_le32(GS_CAN_MODE_START);
684685
dm->flags = cpu_to_le32(flags);
685686
rc = usb_control_msg(interface_to_usbdev(dev->iface),
@@ -696,13 +697,12 @@ static int gs_can_open(struct net_device *netdev)
696697
if (rc < 0) {
697698
netdev_err(netdev, "Couldn't start device (err=%d)\n", rc);
698699
kfree(dm);
700+
dev->can.state = CAN_STATE_STOPPED;
699701
return rc;
700702
}
701703

702704
kfree(dm);
703705

704-
dev->can.state = CAN_STATE_ERROR_ACTIVE;
705-
706706
parent->active_channels++;
707707
if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
708708
netif_start_queue(netdev);

0 commit comments

Comments
 (0)