diff options
Diffstat (limited to 'drivers/net/can')
-rw-r--r-- | drivers/net/can/usb/esd_usb2.c | 127 | ||||
-rw-r--r-- | drivers/net/can/usb/kvaser_usb.c | 64 | ||||
-rw-r--r-- | drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 61 | ||||
-rw-r--r-- | drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 1 |
4 files changed, 160 insertions, 93 deletions
diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c index 9b74d1e3ad44..6aa7b3266c80 100644 --- a/drivers/net/can/usb/esd_usb2.c +++ b/drivers/net/can/usb/esd_usb2.c | |||
@@ -612,9 +612,15 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv) | |||
612 | { | 612 | { |
613 | struct esd_usb2 *dev = priv->usb2; | 613 | struct esd_usb2 *dev = priv->usb2; |
614 | struct net_device *netdev = priv->netdev; | 614 | struct net_device *netdev = priv->netdev; |
615 | struct esd_usb2_msg msg; | 615 | struct esd_usb2_msg *msg; |
616 | int err, i; | 616 | int err, i; |
617 | 617 | ||
618 | msg = kmalloc(sizeof(*msg), GFP_KERNEL); | ||
619 | if (!msg) { | ||
620 | err = -ENOMEM; | ||
621 | goto out; | ||
622 | } | ||
623 | |||
618 | /* | 624 | /* |
619 | * Enable all IDs | 625 | * Enable all IDs |
620 | * The IDADD message takes up to 64 32 bit bitmasks (2048 bits). | 626 | * The IDADD message takes up to 64 32 bit bitmasks (2048 bits). |
@@ -628,33 +634,32 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv) | |||
628 | * the number of the starting bitmask (0..64) to the filter.option | 634 | * the number of the starting bitmask (0..64) to the filter.option |
629 | * field followed by only some bitmasks. | 635 | * field followed by only some bitmasks. |
630 | */ | 636 | */ |
631 | msg.msg.hdr.cmd = CMD_IDADD; | 637 | msg->msg.hdr.cmd = CMD_IDADD; |
632 | msg.msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT; | 638 | msg->msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT; |
633 | msg.msg.filter.net = priv->index; | 639 | msg->msg.filter.net = priv->index; |
634 | msg.msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */ | 640 | msg->msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */ |
635 | for (i = 0; i < ESD_MAX_ID_SEGMENT; i++) | 641 | for (i = 0; i < ESD_MAX_ID_SEGMENT; i++) |
636 | msg.msg.filter.mask[i] = cpu_to_le32(0xffffffff); | 642 | msg->msg.filter.mask[i] = cpu_to_le32(0xffffffff); |
637 | /* enable 29bit extended IDs */ | 643 | /* enable 29bit extended IDs */ |
638 | msg.msg.filter.mask[ESD_MAX_ID_SEGMENT] = cpu_to_le32(0x00000001); | 644 | msg->msg.filter.mask[ESD_MAX_ID_SEGMENT] = cpu_to_le32(0x00000001); |
639 | 645 | ||
640 | err = esd_usb2_send_msg(dev, &msg); | 646 | err = esd_usb2_send_msg(dev, msg); |
641 | if (err) | 647 | if (err) |
642 | goto failed; | 648 | goto out; |
643 | 649 | ||
644 | err = esd_usb2_setup_rx_urbs(dev); | 650 | err = esd_usb2_setup_rx_urbs(dev); |
645 | if (err) | 651 | if (err) |
646 | goto failed; | 652 | goto out; |
647 | 653 | ||
648 | priv->can.state = CAN_STATE_ERROR_ACTIVE; | 654 | priv->can.state = CAN_STATE_ERROR_ACTIVE; |
649 | 655 | ||
650 | return 0; | 656 | out: |
651 | |||
652 | failed: | ||
653 | if (err == -ENODEV) | 657 | if (err == -ENODEV) |
654 | netif_device_detach(netdev); | 658 | netif_device_detach(netdev); |
659 | if (err) | ||
660 | netdev_err(netdev, "couldn't start device: %d\n", err); | ||
655 | 661 | ||
656 | netdev_err(netdev, "couldn't start device: %d\n", err); | 662 | kfree(msg); |
657 | |||
658 | return err; | 663 | return err; |
659 | } | 664 | } |
660 | 665 | ||
@@ -833,26 +838,30 @@ nourbmem: | |||
833 | static int esd_usb2_close(struct net_device *netdev) | 838 | static int esd_usb2_close(struct net_device *netdev) |
834 | { | 839 | { |
835 | struct esd_usb2_net_priv *priv = netdev_priv(netdev); | 840 | struct esd_usb2_net_priv *priv = netdev_priv(netdev); |
836 | struct esd_usb2_msg msg; | 841 | struct esd_usb2_msg *msg; |
837 | int i; | 842 | int i; |
838 | 843 | ||
844 | msg = kmalloc(sizeof(*msg), GFP_KERNEL); | ||
845 | if (!msg) | ||
846 | return -ENOMEM; | ||
847 | |||
839 | /* Disable all IDs (see esd_usb2_start()) */ | 848 | /* Disable all IDs (see esd_usb2_start()) */ |
840 | msg.msg.hdr.cmd = CMD_IDADD; | 849 | msg->msg.hdr.cmd = CMD_IDADD; |
841 | msg.msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT; | 850 | msg->msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT; |
842 | msg.msg.filter.net = priv->index; | 851 | msg->msg.filter.net = priv->index; |
843 | msg.msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */ | 852 | msg->msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */ |
844 | for (i = 0; i <= ESD_MAX_ID_SEGMENT; i++) | 853 | for (i = 0; i <= ESD_MAX_ID_SEGMENT; i++) |
845 | msg.msg.filter.mask[i] = 0; | 854 | msg->msg.filter.mask[i] = 0; |
846 | if (esd_usb2_send_msg(priv->usb2, &msg) < 0) | 855 | if (esd_usb2_send_msg(priv->usb2, msg) < 0) |
847 | netdev_err(netdev, "sending idadd message failed\n"); | 856 | netdev_err(netdev, "sending idadd message failed\n"); |
848 | 857 | ||
849 | /* set CAN controller to reset mode */ | 858 | /* set CAN controller to reset mode */ |
850 | msg.msg.hdr.len = 2; | 859 | msg->msg.hdr.len = 2; |
851 | msg.msg.hdr.cmd = CMD_SETBAUD; | 860 | msg->msg.hdr.cmd = CMD_SETBAUD; |
852 | msg.msg.setbaud.net = priv->index; | 861 | msg->msg.setbaud.net = priv->index; |
853 | msg.msg.setbaud.rsvd = 0; | 862 | msg->msg.setbaud.rsvd = 0; |
854 | msg.msg.setbaud.baud = cpu_to_le32(ESD_USB2_NO_BAUDRATE); | 863 | msg->msg.setbaud.baud = cpu_to_le32(ESD_USB2_NO_BAUDRATE); |
855 | if (esd_usb2_send_msg(priv->usb2, &msg) < 0) | 864 | if (esd_usb2_send_msg(priv->usb2, msg) < 0) |
856 | netdev_err(netdev, "sending setbaud message failed\n"); | 865 | netdev_err(netdev, "sending setbaud message failed\n"); |
857 | 866 | ||
858 | priv->can.state = CAN_STATE_STOPPED; | 867 | priv->can.state = CAN_STATE_STOPPED; |
@@ -861,6 +870,8 @@ static int esd_usb2_close(struct net_device *netdev) | |||
861 | 870 | ||
862 | close_candev(netdev); | 871 | close_candev(netdev); |
863 | 872 | ||
873 | kfree(msg); | ||
874 | |||
864 | return 0; | 875 | return 0; |
865 | } | 876 | } |
866 | 877 | ||
@@ -886,7 +897,8 @@ static int esd_usb2_set_bittiming(struct net_device *netdev) | |||
886 | { | 897 | { |
887 | struct esd_usb2_net_priv *priv = netdev_priv(netdev); | 898 | struct esd_usb2_net_priv *priv = netdev_priv(netdev); |
888 | struct can_bittiming *bt = &priv->can.bittiming; | 899 | struct can_bittiming *bt = &priv->can.bittiming; |
889 | struct esd_usb2_msg msg; | 900 | struct esd_usb2_msg *msg; |
901 | int err; | ||
890 | u32 canbtr; | 902 | u32 canbtr; |
891 | int sjw_shift; | 903 | int sjw_shift; |
892 | 904 | ||
@@ -912,15 +924,22 @@ static int esd_usb2_set_bittiming(struct net_device *netdev) | |||
912 | if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) | 924 | if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) |
913 | canbtr |= ESD_USB2_3_SAMPLES; | 925 | canbtr |= ESD_USB2_3_SAMPLES; |
914 | 926 | ||
915 | msg.msg.hdr.len = 2; | 927 | msg = kmalloc(sizeof(*msg), GFP_KERNEL); |
916 | msg.msg.hdr.cmd = CMD_SETBAUD; | 928 | if (!msg) |
917 | msg.msg.setbaud.net = priv->index; | 929 | return -ENOMEM; |
918 | msg.msg.setbaud.rsvd = 0; | 930 | |
919 | msg.msg.setbaud.baud = cpu_to_le32(canbtr); | 931 | msg->msg.hdr.len = 2; |
932 | msg->msg.hdr.cmd = CMD_SETBAUD; | ||
933 | msg->msg.setbaud.net = priv->index; | ||
934 | msg->msg.setbaud.rsvd = 0; | ||
935 | msg->msg.setbaud.baud = cpu_to_le32(canbtr); | ||
920 | 936 | ||
921 | netdev_info(netdev, "setting BTR=%#x\n", canbtr); | 937 | netdev_info(netdev, "setting BTR=%#x\n", canbtr); |
922 | 938 | ||
923 | return esd_usb2_send_msg(priv->usb2, &msg); | 939 | err = esd_usb2_send_msg(priv->usb2, msg); |
940 | |||
941 | kfree(msg); | ||
942 | return err; | ||
924 | } | 943 | } |
925 | 944 | ||
926 | static int esd_usb2_get_berr_counter(const struct net_device *netdev, | 945 | static int esd_usb2_get_berr_counter(const struct net_device *netdev, |
@@ -1022,7 +1041,7 @@ static int esd_usb2_probe(struct usb_interface *intf, | |||
1022 | const struct usb_device_id *id) | 1041 | const struct usb_device_id *id) |
1023 | { | 1042 | { |
1024 | struct esd_usb2 *dev; | 1043 | struct esd_usb2 *dev; |
1025 | struct esd_usb2_msg msg; | 1044 | struct esd_usb2_msg *msg; |
1026 | int i, err; | 1045 | int i, err; |
1027 | 1046 | ||
1028 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 1047 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
@@ -1037,27 +1056,33 @@ static int esd_usb2_probe(struct usb_interface *intf, | |||
1037 | 1056 | ||
1038 | usb_set_intfdata(intf, dev); | 1057 | usb_set_intfdata(intf, dev); |
1039 | 1058 | ||
1059 | msg = kmalloc(sizeof(*msg), GFP_KERNEL); | ||
1060 | if (!msg) { | ||
1061 | err = -ENOMEM; | ||
1062 | goto free_msg; | ||
1063 | } | ||
1064 | |||
1040 | /* query number of CAN interfaces (nets) */ | 1065 | /* query number of CAN interfaces (nets) */ |
1041 | msg.msg.hdr.cmd = CMD_VERSION; | 1066 | msg->msg.hdr.cmd = CMD_VERSION; |
1042 | msg.msg.hdr.len = 2; | 1067 | msg->msg.hdr.len = 2; |
1043 | msg.msg.version.rsvd = 0; | 1068 | msg->msg.version.rsvd = 0; |
1044 | msg.msg.version.flags = 0; | 1069 | msg->msg.version.flags = 0; |
1045 | msg.msg.version.drv_version = 0; | 1070 | msg->msg.version.drv_version = 0; |
1046 | 1071 | ||
1047 | err = esd_usb2_send_msg(dev, &msg); | 1072 | err = esd_usb2_send_msg(dev, msg); |
1048 | if (err < 0) { | 1073 | if (err < 0) { |
1049 | dev_err(&intf->dev, "sending version message failed\n"); | 1074 | dev_err(&intf->dev, "sending version message failed\n"); |
1050 | goto free_dev; | 1075 | goto free_msg; |
1051 | } | 1076 | } |
1052 | 1077 | ||
1053 | err = esd_usb2_wait_msg(dev, &msg); | 1078 | err = esd_usb2_wait_msg(dev, msg); |
1054 | if (err < 0) { | 1079 | if (err < 0) { |
1055 | dev_err(&intf->dev, "no version message answer\n"); | 1080 | dev_err(&intf->dev, "no version message answer\n"); |
1056 | goto free_dev; | 1081 | goto free_msg; |
1057 | } | 1082 | } |
1058 | 1083 | ||
1059 | dev->net_count = (int)msg.msg.version_reply.nets; | 1084 | dev->net_count = (int)msg->msg.version_reply.nets; |
1060 | dev->version = le32_to_cpu(msg.msg.version_reply.version); | 1085 | dev->version = le32_to_cpu(msg->msg.version_reply.version); |
1061 | 1086 | ||
1062 | if (device_create_file(&intf->dev, &dev_attr_firmware)) | 1087 | if (device_create_file(&intf->dev, &dev_attr_firmware)) |
1063 | dev_err(&intf->dev, | 1088 | dev_err(&intf->dev, |
@@ -1075,10 +1100,10 @@ static int esd_usb2_probe(struct usb_interface *intf, | |||
1075 | for (i = 0; i < dev->net_count; i++) | 1100 | for (i = 0; i < dev->net_count; i++) |
1076 | esd_usb2_probe_one_net(intf, i); | 1101 | esd_usb2_probe_one_net(intf, i); |
1077 | 1102 | ||
1078 | return 0; | 1103 | free_msg: |
1079 | 1104 | kfree(msg); | |
1080 | free_dev: | 1105 | if (err) |
1081 | kfree(dev); | 1106 | kfree(dev); |
1082 | done: | 1107 | done: |
1083 | return err; | 1108 | return err; |
1084 | } | 1109 | } |
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c index 45cb9f3c1324..3b9546588240 100644 --- a/drivers/net/can/usb/kvaser_usb.c +++ b/drivers/net/can/usb/kvaser_usb.c | |||
@@ -136,6 +136,9 @@ | |||
136 | #define KVASER_CTRL_MODE_SELFRECEPTION 3 | 136 | #define KVASER_CTRL_MODE_SELFRECEPTION 3 |
137 | #define KVASER_CTRL_MODE_OFF 4 | 137 | #define KVASER_CTRL_MODE_OFF 4 |
138 | 138 | ||
139 | /* log message */ | ||
140 | #define KVASER_EXTENDED_FRAME BIT(31) | ||
141 | |||
139 | struct kvaser_msg_simple { | 142 | struct kvaser_msg_simple { |
140 | u8 tid; | 143 | u8 tid; |
141 | u8 channel; | 144 | u8 channel; |
@@ -817,8 +820,13 @@ static void kvaser_usb_rx_can_msg(const struct kvaser_usb *dev, | |||
817 | priv = dev->nets[channel]; | 820 | priv = dev->nets[channel]; |
818 | stats = &priv->netdev->stats; | 821 | stats = &priv->netdev->stats; |
819 | 822 | ||
820 | if (msg->u.rx_can.flag & (MSG_FLAG_ERROR_FRAME | MSG_FLAG_NERR | | 823 | if ((msg->u.rx_can.flag & MSG_FLAG_ERROR_FRAME) && |
821 | MSG_FLAG_OVERRUN)) { | 824 | (msg->id == CMD_LOG_MESSAGE)) { |
825 | kvaser_usb_rx_error(dev, msg); | ||
826 | return; | ||
827 | } else if (msg->u.rx_can.flag & (MSG_FLAG_ERROR_FRAME | | ||
828 | MSG_FLAG_NERR | | ||
829 | MSG_FLAG_OVERRUN)) { | ||
822 | kvaser_usb_rx_can_err(priv, msg); | 830 | kvaser_usb_rx_can_err(priv, msg); |
823 | return; | 831 | return; |
824 | } else if (msg->u.rx_can.flag & ~MSG_FLAG_REMOTE_FRAME) { | 832 | } else if (msg->u.rx_can.flag & ~MSG_FLAG_REMOTE_FRAME) { |
@@ -834,22 +842,40 @@ static void kvaser_usb_rx_can_msg(const struct kvaser_usb *dev, | |||
834 | return; | 842 | return; |
835 | } | 843 | } |
836 | 844 | ||
837 | cf->can_id = ((msg->u.rx_can.msg[0] & 0x1f) << 6) | | 845 | if (msg->id == CMD_LOG_MESSAGE) { |
838 | (msg->u.rx_can.msg[1] & 0x3f); | 846 | cf->can_id = le32_to_cpu(msg->u.log_message.id); |
839 | cf->can_dlc = get_can_dlc(msg->u.rx_can.msg[5]); | 847 | if (cf->can_id & KVASER_EXTENDED_FRAME) |
848 | cf->can_id &= CAN_EFF_MASK | CAN_EFF_FLAG; | ||
849 | else | ||
850 | cf->can_id &= CAN_SFF_MASK; | ||
840 | 851 | ||
841 | if (msg->id == CMD_RX_EXT_MESSAGE) { | 852 | cf->can_dlc = get_can_dlc(msg->u.log_message.dlc); |
842 | cf->can_id <<= 18; | ||
843 | cf->can_id |= ((msg->u.rx_can.msg[2] & 0x0f) << 14) | | ||
844 | ((msg->u.rx_can.msg[3] & 0xff) << 6) | | ||
845 | (msg->u.rx_can.msg[4] & 0x3f); | ||
846 | cf->can_id |= CAN_EFF_FLAG; | ||
847 | } | ||
848 | 853 | ||
849 | if (msg->u.rx_can.flag & MSG_FLAG_REMOTE_FRAME) | 854 | if (msg->u.log_message.flags & MSG_FLAG_REMOTE_FRAME) |
850 | cf->can_id |= CAN_RTR_FLAG; | 855 | cf->can_id |= CAN_RTR_FLAG; |
851 | else | 856 | else |
852 | memcpy(cf->data, &msg->u.rx_can.msg[6], cf->can_dlc); | 857 | memcpy(cf->data, &msg->u.log_message.data, |
858 | cf->can_dlc); | ||
859 | } else { | ||
860 | cf->can_id = ((msg->u.rx_can.msg[0] & 0x1f) << 6) | | ||
861 | (msg->u.rx_can.msg[1] & 0x3f); | ||
862 | |||
863 | if (msg->id == CMD_RX_EXT_MESSAGE) { | ||
864 | cf->can_id <<= 18; | ||
865 | cf->can_id |= ((msg->u.rx_can.msg[2] & 0x0f) << 14) | | ||
866 | ((msg->u.rx_can.msg[3] & 0xff) << 6) | | ||
867 | (msg->u.rx_can.msg[4] & 0x3f); | ||
868 | cf->can_id |= CAN_EFF_FLAG; | ||
869 | } | ||
870 | |||
871 | cf->can_dlc = get_can_dlc(msg->u.rx_can.msg[5]); | ||
872 | |||
873 | if (msg->u.rx_can.flag & MSG_FLAG_REMOTE_FRAME) | ||
874 | cf->can_id |= CAN_RTR_FLAG; | ||
875 | else | ||
876 | memcpy(cf->data, &msg->u.rx_can.msg[6], | ||
877 | cf->can_dlc); | ||
878 | } | ||
853 | 879 | ||
854 | netif_rx(skb); | 880 | netif_rx(skb); |
855 | 881 | ||
@@ -911,6 +937,7 @@ static void kvaser_usb_handle_message(const struct kvaser_usb *dev, | |||
911 | 937 | ||
912 | case CMD_RX_STD_MESSAGE: | 938 | case CMD_RX_STD_MESSAGE: |
913 | case CMD_RX_EXT_MESSAGE: | 939 | case CMD_RX_EXT_MESSAGE: |
940 | case CMD_LOG_MESSAGE: | ||
914 | kvaser_usb_rx_can_msg(dev, msg); | 941 | kvaser_usb_rx_can_msg(dev, msg); |
915 | break; | 942 | break; |
916 | 943 | ||
@@ -919,11 +946,6 @@ static void kvaser_usb_handle_message(const struct kvaser_usb *dev, | |||
919 | kvaser_usb_rx_error(dev, msg); | 946 | kvaser_usb_rx_error(dev, msg); |
920 | break; | 947 | break; |
921 | 948 | ||
922 | case CMD_LOG_MESSAGE: | ||
923 | if (msg->u.log_message.flags & MSG_FLAG_ERROR_FRAME) | ||
924 | kvaser_usb_rx_error(dev, msg); | ||
925 | break; | ||
926 | |||
927 | case CMD_TX_ACKNOWLEDGE: | 949 | case CMD_TX_ACKNOWLEDGE: |
928 | kvaser_usb_tx_acknowledge(dev, msg); | 950 | kvaser_usb_tx_acknowledge(dev, msg); |
929 | break; | 951 | break; |
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 30d79bfa5b10..8ee9d1556e6e 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c | |||
@@ -504,15 +504,24 @@ static int pcan_usb_pro_restart_async(struct peak_usb_device *dev, | |||
504 | return usb_submit_urb(urb, GFP_ATOMIC); | 504 | return usb_submit_urb(urb, GFP_ATOMIC); |
505 | } | 505 | } |
506 | 506 | ||
507 | static void pcan_usb_pro_drv_loaded(struct peak_usb_device *dev, int loaded) | 507 | static int pcan_usb_pro_drv_loaded(struct peak_usb_device *dev, int loaded) |
508 | { | 508 | { |
509 | u8 buffer[16]; | 509 | u8 *buffer; |
510 | int err; | ||
511 | |||
512 | buffer = kmalloc(PCAN_USBPRO_FCT_DRVLD_REQ_LEN, GFP_KERNEL); | ||
513 | if (!buffer) | ||
514 | return -ENOMEM; | ||
510 | 515 | ||
511 | buffer[0] = 0; | 516 | buffer[0] = 0; |
512 | buffer[1] = !!loaded; | 517 | buffer[1] = !!loaded; |
513 | 518 | ||
514 | pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_FCT, | 519 | err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_FCT, |
515 | PCAN_USBPRO_FCT_DRVLD, buffer, sizeof(buffer)); | 520 | PCAN_USBPRO_FCT_DRVLD, buffer, |
521 | PCAN_USBPRO_FCT_DRVLD_REQ_LEN); | ||
522 | kfree(buffer); | ||
523 | |||
524 | return err; | ||
516 | } | 525 | } |
517 | 526 | ||
518 | static inline | 527 | static inline |
@@ -851,21 +860,24 @@ static int pcan_usb_pro_stop(struct peak_usb_device *dev) | |||
851 | */ | 860 | */ |
852 | static int pcan_usb_pro_init(struct peak_usb_device *dev) | 861 | static int pcan_usb_pro_init(struct peak_usb_device *dev) |
853 | { | 862 | { |
854 | struct pcan_usb_pro_interface *usb_if; | ||
855 | struct pcan_usb_pro_device *pdev = | 863 | struct pcan_usb_pro_device *pdev = |
856 | container_of(dev, struct pcan_usb_pro_device, dev); | 864 | container_of(dev, struct pcan_usb_pro_device, dev); |
865 | struct pcan_usb_pro_interface *usb_if = NULL; | ||
866 | struct pcan_usb_pro_fwinfo *fi = NULL; | ||
867 | struct pcan_usb_pro_blinfo *bi = NULL; | ||
868 | int err; | ||
857 | 869 | ||
858 | /* do this for 1st channel only */ | 870 | /* do this for 1st channel only */ |
859 | if (!dev->prev_siblings) { | 871 | if (!dev->prev_siblings) { |
860 | struct pcan_usb_pro_fwinfo fi; | ||
861 | struct pcan_usb_pro_blinfo bi; | ||
862 | int err; | ||
863 | |||
864 | /* allocate netdevices common structure attached to first one */ | 872 | /* allocate netdevices common structure attached to first one */ |
865 | usb_if = kzalloc(sizeof(struct pcan_usb_pro_interface), | 873 | usb_if = kzalloc(sizeof(struct pcan_usb_pro_interface), |
866 | GFP_KERNEL); | 874 | GFP_KERNEL); |
867 | if (!usb_if) | 875 | fi = kmalloc(sizeof(struct pcan_usb_pro_fwinfo), GFP_KERNEL); |
868 | return -ENOMEM; | 876 | bi = kmalloc(sizeof(struct pcan_usb_pro_blinfo), GFP_KERNEL); |
877 | if (!usb_if || !fi || !bi) { | ||
878 | err = -ENOMEM; | ||
879 | goto err_out; | ||
880 | } | ||
869 | 881 | ||
870 | /* number of ts msgs to ignore before taking one into account */ | 882 | /* number of ts msgs to ignore before taking one into account */ |
871 | usb_if->cm_ignore_count = 5; | 883 | usb_if->cm_ignore_count = 5; |
@@ -877,34 +889,34 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev) | |||
877 | */ | 889 | */ |
878 | err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO, | 890 | err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO, |
879 | PCAN_USBPRO_INFO_FW, | 891 | PCAN_USBPRO_INFO_FW, |
880 | &fi, sizeof(fi)); | 892 | fi, sizeof(*fi)); |
881 | if (err) { | 893 | if (err) { |
882 | kfree(usb_if); | ||
883 | dev_err(dev->netdev->dev.parent, | 894 | dev_err(dev->netdev->dev.parent, |
884 | "unable to read %s firmware info (err %d)\n", | 895 | "unable to read %s firmware info (err %d)\n", |
885 | pcan_usb_pro.name, err); | 896 | pcan_usb_pro.name, err); |
886 | return err; | 897 | goto err_out; |
887 | } | 898 | } |
888 | 899 | ||
889 | err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO, | 900 | err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO, |
890 | PCAN_USBPRO_INFO_BL, | 901 | PCAN_USBPRO_INFO_BL, |
891 | &bi, sizeof(bi)); | 902 | bi, sizeof(*bi)); |
892 | if (err) { | 903 | if (err) { |
893 | kfree(usb_if); | ||
894 | dev_err(dev->netdev->dev.parent, | 904 | dev_err(dev->netdev->dev.parent, |
895 | "unable to read %s bootloader info (err %d)\n", | 905 | "unable to read %s bootloader info (err %d)\n", |
896 | pcan_usb_pro.name, err); | 906 | pcan_usb_pro.name, err); |
897 | return err; | 907 | goto err_out; |
898 | } | 908 | } |
899 | 909 | ||
910 | /* tell the device the can driver is running */ | ||
911 | err = pcan_usb_pro_drv_loaded(dev, 1); | ||
912 | if (err) | ||
913 | goto err_out; | ||
914 | |||
900 | dev_info(dev->netdev->dev.parent, | 915 | dev_info(dev->netdev->dev.parent, |
901 | "PEAK-System %s hwrev %u serial %08X.%08X (%u channels)\n", | 916 | "PEAK-System %s hwrev %u serial %08X.%08X (%u channels)\n", |
902 | pcan_usb_pro.name, | 917 | pcan_usb_pro.name, |
903 | bi.hw_rev, bi.serial_num_hi, bi.serial_num_lo, | 918 | bi->hw_rev, bi->serial_num_hi, bi->serial_num_lo, |
904 | pcan_usb_pro.ctrl_count); | 919 | pcan_usb_pro.ctrl_count); |
905 | |||
906 | /* tell the device the can driver is running */ | ||
907 | pcan_usb_pro_drv_loaded(dev, 1); | ||
908 | } else { | 920 | } else { |
909 | usb_if = pcan_usb_pro_dev_if(dev->prev_siblings); | 921 | usb_if = pcan_usb_pro_dev_if(dev->prev_siblings); |
910 | } | 922 | } |
@@ -916,6 +928,13 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev) | |||
916 | pcan_usb_pro_set_led(dev, 0, 1); | 928 | pcan_usb_pro_set_led(dev, 0, 1); |
917 | 929 | ||
918 | return 0; | 930 | return 0; |
931 | |||
932 | err_out: | ||
933 | kfree(bi); | ||
934 | kfree(fi); | ||
935 | kfree(usb_if); | ||
936 | |||
937 | return err; | ||
919 | } | 938 | } |
920 | 939 | ||
921 | static void pcan_usb_pro_exit(struct peak_usb_device *dev) | 940 | static void pcan_usb_pro_exit(struct peak_usb_device *dev) |
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.h b/drivers/net/can/usb/peak_usb/pcan_usb_pro.h index a869918c5620..32275af547e0 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.h +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.h | |||
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | /* Vendor Request value for XXX_FCT */ | 30 | /* Vendor Request value for XXX_FCT */ |
31 | #define PCAN_USBPRO_FCT_DRVLD 5 /* tell device driver is loaded */ | 31 | #define PCAN_USBPRO_FCT_DRVLD 5 /* tell device driver is loaded */ |
32 | #define PCAN_USBPRO_FCT_DRVLD_REQ_LEN 16 | ||
32 | 33 | ||
33 | /* PCAN_USBPRO_INFO_BL vendor request record type */ | 34 | /* PCAN_USBPRO_INFO_BL vendor request record type */ |
34 | struct __packed pcan_usb_pro_blinfo { | 35 | struct __packed pcan_usb_pro_blinfo { |