]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
can: peak_usb: fix USB FD devices potential malfunction
authorStephane Grosjean <stephane.grosjean@hms-networks.com>
Thu, 24 Jul 2025 08:13:19 +0000 (10:13 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Fri, 25 Jul 2025 10:09:19 +0000 (12:09 +0200)
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: 4f232482467a ("can: peak_usb: include support for a new MCU")
Signed-off-by: Stephane Grosjean <stephane.grosjean@hms-networks.com>
Link: https://patch.msgid.link/20250724081550.11694-1-stephane.grosjean@free.fr
Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
[mkl: rephrase commit message]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/peak_usb/pcan_usb_fd.c

index 4d85b29a17b787e0b11804f9375cbcce8ae5a393..ebefc274b50a5f93600af4aa101aaca5769ca48d 100644 (file)
@@ -49,7 +49,7 @@ struct __packed pcan_ufd_fw_info {
        __le32  ser_no;         /* S/N */
        __le32  flags;          /* special functions */
 
-       /* extended data when type == PCAN_USBFD_TYPE_EXT */
+       /* extended data when type >= PCAN_USBFD_TYPE_EXT */
        u8      cmd_out_ep;     /* ep for cmd */
        u8      cmd_in_ep;      /* ep for replies */
        u8      data_out_ep[2]; /* ep for CANx TX */
@@ -982,10 +982,11 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
                        dev->can.ctrlmode |= CAN_CTRLMODE_FD_NON_ISO;
                }
 
-               /* if vendor rsp is of type 2, then it contains EP numbers to
-                * use for cmds pipes. If not, then default EP should be used.
+               /* if vendor rsp type is greater than or equal to 2, then it
+                * contains EP numbers to use for cmds pipes. If not, then
+                * default EP should be used.
                 */
-               if (fw_info->type != cpu_to_le16(PCAN_USBFD_TYPE_EXT)) {
+               if (le16_to_cpu(fw_info->type) < PCAN_USBFD_TYPE_EXT) {
                        fw_info->cmd_out_ep = PCAN_USBPRO_EP_CMDOUT;
                        fw_info->cmd_in_ep = PCAN_USBPRO_EP_CMDIN;
                }
@@ -1018,11 +1019,11 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
        dev->can_channel_id =
                le32_to_cpu(pdev->usb_if->fw_info.dev_id[dev->ctrl_idx]);
 
-       /* if vendor rsp is of type 2, then it contains EP numbers to
-        * use for data pipes. If not, then statically defined EP are used
-        * (see peak_usb_create_dev()).
+       /* if vendor rsp type is greater than or equal to 2, then it contains EP
+        * numbers to use for data pipes. If not, then statically defined EP are
+        * used (see peak_usb_create_dev()).
         */
-       if (fw_info->type == cpu_to_le16(PCAN_USBFD_TYPE_EXT)) {
+       if (le16_to_cpu(fw_info->type) >= PCAN_USBFD_TYPE_EXT) {
                dev->ep_msg_in = fw_info->data_in_ep;
                dev->ep_msg_out = fw_info->data_out_ep[dev->ctrl_idx];
        }