Commit ceaca9dc authored by David S. Miller's avatar David S. Miller

Merge tag 'linux-can-fixes-for-3.18-20141207' of git://gitorious.org/linux-can/linux-can

Marc Kleine-Budde says:

====================
pull-request: can 2014-12-07

this is a pull request of three patches by Stephane Grosjean which fix several
bugs in the peak_usb CAN drivers.

Please queue, if possible for 3.18, if it's too late these patches takes the
slow lane via net-next.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 51de7bb9 62bc24f6
...@@ -316,7 +316,7 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number) ...@@ -316,7 +316,7 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number)
if (err) { if (err) {
netdev_err(dev->netdev, "getting serial failure: %d\n", err); netdev_err(dev->netdev, "getting serial failure: %d\n", err);
} else if (serial_number) { } else if (serial_number) {
u32 tmp32; __le32 tmp32;
memcpy(&tmp32, args, 4); memcpy(&tmp32, args, 4);
*serial_number = le32_to_cpu(tmp32); *serial_number = le32_to_cpu(tmp32);
...@@ -347,7 +347,7 @@ static int pcan_usb_get_device_id(struct peak_usb_device *dev, u32 *device_id) ...@@ -347,7 +347,7 @@ static int pcan_usb_get_device_id(struct peak_usb_device *dev, u32 *device_id)
*/ */
static int pcan_usb_update_ts(struct pcan_usb_msg_context *mc) static int pcan_usb_update_ts(struct pcan_usb_msg_context *mc)
{ {
u16 tmp16; __le16 tmp16;
if ((mc->ptr+2) > mc->end) if ((mc->ptr+2) > mc->end)
return -EINVAL; return -EINVAL;
...@@ -371,7 +371,7 @@ static int pcan_usb_decode_ts(struct pcan_usb_msg_context *mc, u8 first_packet) ...@@ -371,7 +371,7 @@ static int pcan_usb_decode_ts(struct pcan_usb_msg_context *mc, u8 first_packet)
{ {
/* only 1st packet supplies a word timestamp */ /* only 1st packet supplies a word timestamp */
if (first_packet) { if (first_packet) {
u16 tmp16; __le16 tmp16;
if ((mc->ptr + 2) > mc->end) if ((mc->ptr + 2) > mc->end)
return -EINVAL; return -EINVAL;
...@@ -614,7 +614,7 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) ...@@ -614,7 +614,7 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
return -ENOMEM; return -ENOMEM;
if (status_len & PCAN_USB_STATUSLEN_EXT_ID) { if (status_len & PCAN_USB_STATUSLEN_EXT_ID) {
u32 tmp32; __le32 tmp32;
if ((mc->ptr + 4) > mc->end) if ((mc->ptr + 4) > mc->end)
goto decode_failed; goto decode_failed;
...@@ -622,9 +622,9 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) ...@@ -622,9 +622,9 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
memcpy(&tmp32, mc->ptr, 4); memcpy(&tmp32, mc->ptr, 4);
mc->ptr += 4; mc->ptr += 4;
cf->can_id = le32_to_cpu(tmp32 >> 3) | CAN_EFF_FLAG; cf->can_id = (le32_to_cpu(tmp32) >> 3) | CAN_EFF_FLAG;
} else { } else {
u16 tmp16; __le16 tmp16;
if ((mc->ptr + 2) > mc->end) if ((mc->ptr + 2) > mc->end)
goto decode_failed; goto decode_failed;
...@@ -632,7 +632,7 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) ...@@ -632,7 +632,7 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
memcpy(&tmp16, mc->ptr, 2); memcpy(&tmp16, mc->ptr, 2);
mc->ptr += 2; mc->ptr += 2;
cf->can_id = le16_to_cpu(tmp16 >> 5); cf->can_id = le16_to_cpu(tmp16) >> 5;
} }
cf->can_dlc = get_can_dlc(rec_len); cf->can_dlc = get_can_dlc(rec_len);
......
...@@ -735,7 +735,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -735,7 +735,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
dev->cmd_buf = kmalloc(PCAN_USB_MAX_CMD_LEN, GFP_KERNEL); dev->cmd_buf = kmalloc(PCAN_USB_MAX_CMD_LEN, GFP_KERNEL);
if (!dev->cmd_buf) { if (!dev->cmd_buf) {
err = -ENOMEM; err = -ENOMEM;
goto lbl_set_intf_data; goto lbl_free_candev;
} }
dev->udev = usb_dev; dev->udev = usb_dev;
...@@ -775,7 +775,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -775,7 +775,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
err = register_candev(netdev); err = register_candev(netdev);
if (err) { if (err) {
dev_err(&intf->dev, "couldn't register CAN device: %d\n", err); dev_err(&intf->dev, "couldn't register CAN device: %d\n", err);
goto lbl_free_cmd_buf; goto lbl_restore_intf_data;
} }
if (dev->prev_siblings) if (dev->prev_siblings)
...@@ -788,14 +788,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -788,14 +788,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
if (dev->adapter->dev_init) { if (dev->adapter->dev_init) {
err = dev->adapter->dev_init(dev); err = dev->adapter->dev_init(dev);
if (err) if (err)
goto lbl_free_cmd_buf; goto lbl_unregister_candev;
} }
/* set bus off */ /* set bus off */
if (dev->adapter->dev_set_bus) { if (dev->adapter->dev_set_bus) {
err = dev->adapter->dev_set_bus(dev, 0); err = dev->adapter->dev_set_bus(dev, 0);
if (err) if (err)
goto lbl_free_cmd_buf; goto lbl_unregister_candev;
} }
/* get device number early */ /* get device number early */
...@@ -807,11 +807,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -807,11 +807,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
return 0; return 0;
lbl_free_cmd_buf: lbl_unregister_candev:
kfree(dev->cmd_buf); unregister_candev(netdev);
lbl_set_intf_data: lbl_restore_intf_data:
usb_set_intfdata(intf, dev->prev_siblings); usb_set_intfdata(intf, dev->prev_siblings);
kfree(dev->cmd_buf);
lbl_free_candev:
free_candev(netdev); free_candev(netdev);
return err; return err;
...@@ -853,6 +856,7 @@ static int peak_usb_probe(struct usb_interface *intf, ...@@ -853,6 +856,7 @@ static int peak_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct usb_device *usb_dev = interface_to_usbdev(intf); struct usb_device *usb_dev = interface_to_usbdev(intf);
const u16 usb_id_product = le16_to_cpu(usb_dev->descriptor.idProduct);
struct peak_usb_adapter *peak_usb_adapter, **pp; struct peak_usb_adapter *peak_usb_adapter, **pp;
int i, err = -ENOMEM; int i, err = -ENOMEM;
...@@ -860,7 +864,7 @@ static int peak_usb_probe(struct usb_interface *intf, ...@@ -860,7 +864,7 @@ static int peak_usb_probe(struct usb_interface *intf,
/* get corresponding PCAN-USB adapter */ /* get corresponding PCAN-USB adapter */
for (pp = peak_usb_adapters_list; *pp; pp++) for (pp = peak_usb_adapters_list; *pp; pp++)
if ((*pp)->device_id == usb_dev->descriptor.idProduct) if ((*pp)->device_id == usb_id_product)
break; break;
peak_usb_adapter = *pp; peak_usb_adapter = *pp;
......
...@@ -78,8 +78,8 @@ struct pcan_usb_pro_msg { ...@@ -78,8 +78,8 @@ struct pcan_usb_pro_msg {
int rec_buffer_size; int rec_buffer_size;
int rec_buffer_len; int rec_buffer_len;
union { union {
u16 *rec_cnt_rd; __le16 *rec_cnt_rd;
u32 *rec_cnt; __le32 *rec_cnt;
u8 *rec_buffer; u8 *rec_buffer;
} u; } u;
}; };
...@@ -155,7 +155,7 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...) ...@@ -155,7 +155,7 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...)
*pc++ = va_arg(ap, int); *pc++ = va_arg(ap, int);
*pc++ = va_arg(ap, int); *pc++ = va_arg(ap, int);
*pc++ = va_arg(ap, int); *pc++ = va_arg(ap, int);
*(u32 *)pc = cpu_to_le32(va_arg(ap, u32)); *(__le32 *)pc = cpu_to_le32(va_arg(ap, u32));
pc += 4; pc += 4;
memcpy(pc, va_arg(ap, int *), i); memcpy(pc, va_arg(ap, int *), i);
pc += i; pc += i;
...@@ -165,7 +165,7 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...) ...@@ -165,7 +165,7 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...)
case PCAN_USBPRO_GETDEVID: case PCAN_USBPRO_GETDEVID:
*pc++ = va_arg(ap, int); *pc++ = va_arg(ap, int);
pc += 2; pc += 2;
*(u32 *)pc = cpu_to_le32(va_arg(ap, u32)); *(__le32 *)pc = cpu_to_le32(va_arg(ap, u32));
pc += 4; pc += 4;
break; break;
...@@ -173,21 +173,21 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...) ...@@ -173,21 +173,21 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...)
case PCAN_USBPRO_SETBUSACT: case PCAN_USBPRO_SETBUSACT:
case PCAN_USBPRO_SETSILENT: case PCAN_USBPRO_SETSILENT:
*pc++ = va_arg(ap, int); *pc++ = va_arg(ap, int);
*(u16 *)pc = cpu_to_le16(va_arg(ap, int)); *(__le16 *)pc = cpu_to_le16(va_arg(ap, int));
pc += 2; pc += 2;
break; break;
case PCAN_USBPRO_SETLED: case PCAN_USBPRO_SETLED:
*pc++ = va_arg(ap, int); *pc++ = va_arg(ap, int);
*(u16 *)pc = cpu_to_le16(va_arg(ap, int)); *(__le16 *)pc = cpu_to_le16(va_arg(ap, int));
pc += 2; pc += 2;
*(u32 *)pc = cpu_to_le32(va_arg(ap, u32)); *(__le32 *)pc = cpu_to_le32(va_arg(ap, u32));
pc += 4; pc += 4;
break; break;
case PCAN_USBPRO_SETTS: case PCAN_USBPRO_SETTS:
pc++; pc++;
*(u16 *)pc = cpu_to_le16(va_arg(ap, int)); *(__le16 *)pc = cpu_to_le16(va_arg(ap, int));
pc += 2; pc += 2;
break; break;
...@@ -200,7 +200,7 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...) ...@@ -200,7 +200,7 @@ static int pcan_msg_add_rec(struct pcan_usb_pro_msg *pm, u8 id, ...)
len = pc - pm->rec_ptr; len = pc - pm->rec_ptr;
if (len > 0) { if (len > 0) {
*pm->u.rec_cnt = cpu_to_le32(*pm->u.rec_cnt+1); *pm->u.rec_cnt = cpu_to_le32(le32_to_cpu(*pm->u.rec_cnt) + 1);
*pm->rec_ptr = id; *pm->rec_ptr = id;
pm->rec_ptr = pc; pm->rec_ptr = pc;
...@@ -333,8 +333,6 @@ static int pcan_usb_pro_send_req(struct peak_usb_device *dev, int req_id, ...@@ -333,8 +333,6 @@ static int pcan_usb_pro_send_req(struct peak_usb_device *dev, int req_id,
if (!(dev->state & PCAN_USB_STATE_CONNECTED)) if (!(dev->state & PCAN_USB_STATE_CONNECTED))
return 0; return 0;
memset(req_addr, '\0', req_size);
req_type = USB_TYPE_VENDOR | USB_RECIP_OTHER; req_type = USB_TYPE_VENDOR | USB_RECIP_OTHER;
switch (req_id) { switch (req_id) {
...@@ -345,6 +343,7 @@ static int pcan_usb_pro_send_req(struct peak_usb_device *dev, int req_id, ...@@ -345,6 +343,7 @@ static int pcan_usb_pro_send_req(struct peak_usb_device *dev, int req_id,
default: default:
p = usb_rcvctrlpipe(dev->udev, 0); p = usb_rcvctrlpipe(dev->udev, 0);
req_type |= USB_DIR_IN; req_type |= USB_DIR_IN;
memset(req_addr, '\0', req_size);
break; break;
} }
...@@ -572,7 +571,7 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if, ...@@ -572,7 +571,7 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,
static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if, static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if,
struct pcan_usb_pro_rxstatus *er) struct pcan_usb_pro_rxstatus *er)
{ {
const u32 raw_status = le32_to_cpu(er->status); const u16 raw_status = le16_to_cpu(er->status);
const unsigned int ctrl_idx = (er->channel >> 4) & 0x0f; const unsigned int ctrl_idx = (er->channel >> 4) & 0x0f;
struct peak_usb_device *dev = usb_if->dev[ctrl_idx]; struct peak_usb_device *dev = usb_if->dev[ctrl_idx];
struct net_device *netdev = dev->netdev; struct net_device *netdev = dev->netdev;
......
...@@ -33,27 +33,27 @@ ...@@ -33,27 +33,27 @@
/* PCAN_USBPRO_INFO_BL vendor request record type */ /* PCAN_USBPRO_INFO_BL vendor request record type */
struct __packed pcan_usb_pro_blinfo { struct __packed pcan_usb_pro_blinfo {
u32 ctrl_type; __le32 ctrl_type;
u8 version[4]; u8 version[4];
u8 day; u8 day;
u8 month; u8 month;
u8 year; u8 year;
u8 dummy; u8 dummy;
u32 serial_num_hi; __le32 serial_num_hi;
u32 serial_num_lo; __le32 serial_num_lo;
u32 hw_type; __le32 hw_type;
u32 hw_rev; __le32 hw_rev;
}; };
/* PCAN_USBPRO_INFO_FW vendor request record type */ /* PCAN_USBPRO_INFO_FW vendor request record type */
struct __packed pcan_usb_pro_fwinfo { struct __packed pcan_usb_pro_fwinfo {
u32 ctrl_type; __le32 ctrl_type;
u8 version[4]; u8 version[4];
u8 day; u8 day;
u8 month; u8 month;
u8 year; u8 year;
u8 dummy; u8 dummy;
u32 fw_type; __le32 fw_type;
}; };
/* /*
...@@ -80,46 +80,46 @@ struct __packed pcan_usb_pro_fwinfo { ...@@ -80,46 +80,46 @@ struct __packed pcan_usb_pro_fwinfo {
struct __packed pcan_usb_pro_btr { struct __packed pcan_usb_pro_btr {
u8 data_type; u8 data_type;
u8 channel; u8 channel;
u16 dummy; __le16 dummy;
u32 CCBT; __le32 CCBT;
}; };
struct __packed pcan_usb_pro_busact { struct __packed pcan_usb_pro_busact {
u8 data_type; u8 data_type;
u8 channel; u8 channel;
u16 onoff; __le16 onoff;
}; };
struct __packed pcan_usb_pro_silent { struct __packed pcan_usb_pro_silent {
u8 data_type; u8 data_type;
u8 channel; u8 channel;
u16 onoff; __le16 onoff;
}; };
struct __packed pcan_usb_pro_filter { struct __packed pcan_usb_pro_filter {
u8 data_type; u8 data_type;
u8 dummy; u8 dummy;
u16 filter_mode; __le16 filter_mode;
}; };
struct __packed pcan_usb_pro_setts { struct __packed pcan_usb_pro_setts {
u8 data_type; u8 data_type;
u8 dummy; u8 dummy;
u16 mode; __le16 mode;
}; };
struct __packed pcan_usb_pro_devid { struct __packed pcan_usb_pro_devid {
u8 data_type; u8 data_type;
u8 channel; u8 channel;
u16 dummy; __le16 dummy;
u32 serial_num; __le32 serial_num;
}; };
struct __packed pcan_usb_pro_setled { struct __packed pcan_usb_pro_setled {
u8 data_type; u8 data_type;
u8 channel; u8 channel;
u16 mode; __le16 mode;
u32 timeout; __le32 timeout;
}; };
struct __packed pcan_usb_pro_rxmsg { struct __packed pcan_usb_pro_rxmsg {
...@@ -127,8 +127,8 @@ struct __packed pcan_usb_pro_rxmsg { ...@@ -127,8 +127,8 @@ struct __packed pcan_usb_pro_rxmsg {
u8 client; u8 client;
u8 flags; u8 flags;
u8 len; u8 len;
u32 ts32; __le32 ts32;
u32 id; __le32 id;
u8 data[8]; u8 data[8];
}; };
...@@ -141,15 +141,15 @@ struct __packed pcan_usb_pro_rxmsg { ...@@ -141,15 +141,15 @@ struct __packed pcan_usb_pro_rxmsg {
struct __packed pcan_usb_pro_rxstatus { struct __packed pcan_usb_pro_rxstatus {
u8 data_type; u8 data_type;
u8 channel; u8 channel;
u16 status; __le16 status;
u32 ts32; __le32 ts32;
u32 err_frm; __le32 err_frm;
}; };
struct __packed pcan_usb_pro_rxts { struct __packed pcan_usb_pro_rxts {
u8 data_type; u8 data_type;
u8 dummy[3]; u8 dummy[3];
u32 ts64[2]; __le32 ts64[2];
}; };
struct __packed pcan_usb_pro_txmsg { struct __packed pcan_usb_pro_txmsg {
...@@ -157,7 +157,7 @@ struct __packed pcan_usb_pro_txmsg { ...@@ -157,7 +157,7 @@ struct __packed pcan_usb_pro_txmsg {
u8 client; u8 client;
u8 flags; u8 flags;
u8 len; u8 len;
u32 id; __le32 id;
u8 data[8]; u8 data[8];
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment