The user defined device number is stored in the little-endian format in flash memory. The reading functions of this number are modified to take this into account. Signed-off-by: Stephane Grosjean <s.grosjean@xxxxxxxxxxxxxxx> --- drivers/net/can/usb/peak_usb/pcan_usb.c | 4 ++-- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 7 +++++-- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 12 ++++++++---- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c index 954abf43d552..313db844ee52 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -383,7 +383,7 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number) /* * read user device id from device */ -static int pcan_usb_get_user_devid(struct peak_usb_device *dev, u32 *device_id) +static int pcan_usb_get_user_devid(struct peak_usb_device *dev, __le32 *ledevid) { u8 args[PCAN_USB_CMD_ARGS_LEN]; int err; @@ -393,7 +393,7 @@ static int pcan_usb_get_user_devid(struct peak_usb_device *dev, u32 *device_id) netdev_err(dev->netdev, "getting device id failure: %d\n", err); else - *device_id = args[0]; + *ledevid = (__le32)args[0]; return err; } diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c index 871a01e158bc..2c5452f6328c 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c @@ -881,8 +881,12 @@ static int peak_usb_create_dev(const struct peak_usb_adapter *peak_usb_adapter, } /* get device number early */ - if (dev->adapter->dev_get_user_devid) - dev->adapter->dev_get_user_devid(dev, &dev->device_number); + if (dev->adapter->dev_get_user_devid) { + __le32 ledevid; + + if (!dev->adapter->dev_get_user_devid(dev, &ledevid)) + dev->device_number = le32_to_cpu(ledevid); + } netdev_info(netdev, "attached to %s channel %u (device %u)\n", peak_usb_adapter->name, ctrl_idx, dev->device_number); diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h index 52bea954f2a7..03c8f942d684 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h @@ -60,7 +60,7 @@ struct peak_usb_adapter { int (*dev_set_data_bittiming)(struct peak_usb_device *dev, struct can_bittiming *bt); int (*dev_set_bus)(struct peak_usb_device *dev, u8 onoff); - int (*dev_get_user_devid)(struct peak_usb_device *dev, u32 *device_id); + int (*dev_get_user_devid)(struct peak_usb_device *dev, __le32 *ledevid); int (*dev_decode_buf)(struct peak_usb_device *dev, struct urb *urb); int (*dev_encode_msg)(struct peak_usb_device *dev, struct sk_buff *skb, u8 *obuf, size_t *size); diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index ab1a8b797ece..533277b41a02 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -422,7 +422,7 @@ static int pcan_usb_fd_set_bittiming_fast(struct peak_usb_device *dev, /* read user device id from device */ static int pcan_usb_fd_get_user_devid(struct peak_usb_device *dev, - u32 *device_id) + __le32 *ledevid) { struct pcan_usb_fd_device *pdev = container_of(dev, struct pcan_usb_fd_device, dev); @@ -432,10 +432,14 @@ static int pcan_usb_fd_get_user_devid(struct peak_usb_device *dev, err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO, PCAN_USBPRO_INFO_FW, fw_info, sizeof(*fw_info)); - if (!err) - *device_id = le32_to_cpu(fw_info->dev_id[dev->ctrl_idx]); + if (err) + return err; + + *ledevid = fw_info->dev_id[dev->ctrl_idx]; + + return 0; +} - return err; } /* handle restart but in asynchronously way diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c index 6c1f7f8c8f45..4fda5bb509f0 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c @@ -420,7 +420,7 @@ static int pcan_usb_pro_set_led(struct peak_usb_device *dev, u8 mode, } static int pcan_usb_pro_get_user_devid(struct peak_usb_device *dev, - u32 *device_id) + __le32 *ledevid) { struct pcan_usb_pro_devid *pdn; struct pcan_usb_pro_msg um; @@ -439,7 +439,7 @@ static int pcan_usb_pro_get_user_devid(struct peak_usb_device *dev, return err; pdn = (struct pcan_usb_pro_devid *)pc; - *device_id = le32_to_cpu(pdn->dev_num); + *ledevid = pdn->dev_num; return err; } -- 2.25.1