Skip to content

Commit 788199b

Browse files
HMS-stgrmarckleinebudde
authored andcommitted
can: peak_usb: fix USB FD devices potential malfunction
The latest firmware versions of USB CAN FD interfaces export the EP numbers to be used to dialog with the device via the "type" field of a response to a vendor request structure, particularly when its value is greater than or equal to 2. Correct the driver's test of this field. Fixes: 4f23248 ("can: peak_usb: include support for a new MCU") Signed-off-by: Stephane Grosjean <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Vincent Mailhol <[email protected]> [mkl: rephrase commit message] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent c8f1313 commit 788199b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/net/can/usb/peak_usb/pcan_usb_fd.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct __packed pcan_ufd_fw_info {
4949
__le32 ser_no; /* S/N */
5050
__le32 flags; /* special functions */
5151

52-
/* extended data when type == PCAN_USBFD_TYPE_EXT */
52+
/* extended data when type >= PCAN_USBFD_TYPE_EXT */
5353
u8 cmd_out_ep; /* ep for cmd */
5454
u8 cmd_in_ep; /* ep for replies */
5555
u8 data_out_ep[2]; /* ep for CANx TX */
@@ -982,10 +982,11 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
982982
dev->can.ctrlmode |= CAN_CTRLMODE_FD_NON_ISO;
983983
}
984984

985-
/* if vendor rsp is of type 2, then it contains EP numbers to
986-
* use for cmds pipes. If not, then default EP should be used.
985+
/* if vendor rsp type is greater than or equal to 2, then it
986+
* contains EP numbers to use for cmds pipes. If not, then
987+
* default EP should be used.
987988
*/
988-
if (fw_info->type != cpu_to_le16(PCAN_USBFD_TYPE_EXT)) {
989+
if (le16_to_cpu(fw_info->type) < PCAN_USBFD_TYPE_EXT) {
989990
fw_info->cmd_out_ep = PCAN_USBPRO_EP_CMDOUT;
990991
fw_info->cmd_in_ep = PCAN_USBPRO_EP_CMDIN;
991992
}
@@ -1018,11 +1019,11 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
10181019
dev->can_channel_id =
10191020
le32_to_cpu(pdev->usb_if->fw_info.dev_id[dev->ctrl_idx]);
10201021

1021-
/* if vendor rsp is of type 2, then it contains EP numbers to
1022-
* use for data pipes. If not, then statically defined EP are used
1023-
* (see peak_usb_create_dev()).
1022+
/* if vendor rsp type is greater than or equal to 2, then it contains EP
1023+
* numbers to use for data pipes. If not, then statically defined EP are
1024+
* used (see peak_usb_create_dev()).
10241025
*/
1025-
if (fw_info->type == cpu_to_le16(PCAN_USBFD_TYPE_EXT)) {
1026+
if (le16_to_cpu(fw_info->type) >= PCAN_USBFD_TYPE_EXT) {
10261027
dev->ep_msg_in = fw_info->data_in_ep;
10271028
dev->ep_msg_out = fw_info->data_out_ep[dev->ctrl_idx];
10281029
}

0 commit comments

Comments
 (0)