diff options
Diffstat (limited to 'drivers/net/can/usb/kvaser_usb.c')
-rw-r--r-- | drivers/net/can/usb/kvaser_usb.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c index 2928f7003041..a316fa4b91ab 100644 --- a/drivers/net/can/usb/kvaser_usb.c +++ b/drivers/net/can/usb/kvaser_usb.c | |||
@@ -14,6 +14,7 @@ | |||
14 | * Copyright (C) 2015 Valeo S.A. | 14 | * Copyright (C) 2015 Valeo S.A. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/kernel.h> | ||
17 | #include <linux/completion.h> | 18 | #include <linux/completion.h> |
18 | #include <linux/module.h> | 19 | #include <linux/module.h> |
19 | #include <linux/netdevice.h> | 20 | #include <linux/netdevice.h> |
@@ -584,8 +585,15 @@ static int kvaser_usb_wait_msg(const struct kvaser_usb *dev, u8 id, | |||
584 | while (pos <= actual_len - MSG_HEADER_LEN) { | 585 | while (pos <= actual_len - MSG_HEADER_LEN) { |
585 | tmp = buf + pos; | 586 | tmp = buf + pos; |
586 | 587 | ||
587 | if (!tmp->len) | 588 | /* Handle messages crossing the USB endpoint max packet |
588 | break; | 589 | * size boundary. Check kvaser_usb_read_bulk_callback() |
590 | * for further details. | ||
591 | */ | ||
592 | if (tmp->len == 0) { | ||
593 | pos = round_up(pos, | ||
594 | dev->bulk_in->wMaxPacketSize); | ||
595 | continue; | ||
596 | } | ||
589 | 597 | ||
590 | if (pos + tmp->len > actual_len) { | 598 | if (pos + tmp->len > actual_len) { |
591 | dev_err(dev->udev->dev.parent, | 599 | dev_err(dev->udev->dev.parent, |
@@ -787,7 +795,6 @@ static int kvaser_usb_simple_msg_async(struct kvaser_usb_net_priv *priv, | |||
787 | netdev_err(netdev, "Error transmitting URB\n"); | 795 | netdev_err(netdev, "Error transmitting URB\n"); |
788 | usb_unanchor_urb(urb); | 796 | usb_unanchor_urb(urb); |
789 | usb_free_urb(urb); | 797 | usb_free_urb(urb); |
790 | kfree(buf); | ||
791 | return err; | 798 | return err; |
792 | } | 799 | } |
793 | 800 | ||
@@ -1317,8 +1324,19 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb) | |||
1317 | while (pos <= urb->actual_length - MSG_HEADER_LEN) { | 1324 | while (pos <= urb->actual_length - MSG_HEADER_LEN) { |
1318 | msg = urb->transfer_buffer + pos; | 1325 | msg = urb->transfer_buffer + pos; |
1319 | 1326 | ||
1320 | if (!msg->len) | 1327 | /* The Kvaser firmware can only read and write messages that |
1321 | break; | 1328 | * does not cross the USB's endpoint wMaxPacketSize boundary. |
1329 | * If a follow-up command crosses such boundary, firmware puts | ||
1330 | * a placeholder zero-length command in its place then aligns | ||
1331 | * the real command to the next max packet size. | ||
1332 | * | ||
1333 | * Handle such cases or we're going to miss a significant | ||
1334 | * number of events in case of a heavy rx load on the bus. | ||
1335 | */ | ||
1336 | if (msg->len == 0) { | ||
1337 | pos = round_up(pos, dev->bulk_in->wMaxPacketSize); | ||
1338 | continue; | ||
1339 | } | ||
1322 | 1340 | ||
1323 | if (pos + msg->len > urb->actual_length) { | 1341 | if (pos + msg->len > urb->actual_length) { |
1324 | dev_err(dev->udev->dev.parent, "Format error\n"); | 1342 | dev_err(dev->udev->dev.parent, "Format error\n"); |
@@ -1326,7 +1344,6 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb) | |||
1326 | } | 1344 | } |
1327 | 1345 | ||
1328 | kvaser_usb_handle_message(dev, msg); | 1346 | kvaser_usb_handle_message(dev, msg); |
1329 | |||
1330 | pos += msg->len; | 1347 | pos += msg->len; |
1331 | } | 1348 | } |
1332 | 1349 | ||
@@ -1615,8 +1632,7 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb, | |||
1615 | struct urb *urb; | 1632 | struct urb *urb; |
1616 | void *buf; | 1633 | void *buf; |
1617 | struct kvaser_msg *msg; | 1634 | struct kvaser_msg *msg; |
1618 | int i, err; | 1635 | int i, err, ret = NETDEV_TX_OK; |
1619 | int ret = NETDEV_TX_OK; | ||
1620 | u8 *msg_tx_can_flags = NULL; /* GCC */ | 1636 | u8 *msg_tx_can_flags = NULL; /* GCC */ |
1621 | 1637 | ||
1622 | if (can_dropped_invalid_skb(netdev, skb)) | 1638 | if (can_dropped_invalid_skb(netdev, skb)) |
@@ -1634,7 +1650,7 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb, | |||
1634 | if (!buf) { | 1650 | if (!buf) { |
1635 | stats->tx_dropped++; | 1651 | stats->tx_dropped++; |
1636 | dev_kfree_skb(skb); | 1652 | dev_kfree_skb(skb); |
1637 | goto nobufmem; | 1653 | goto freeurb; |
1638 | } | 1654 | } |
1639 | 1655 | ||
1640 | msg = buf; | 1656 | msg = buf; |
@@ -1681,8 +1697,10 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb, | |||
1681 | /* This should never happen; it implies a flow control bug */ | 1697 | /* This should never happen; it implies a flow control bug */ |
1682 | if (!context) { | 1698 | if (!context) { |
1683 | netdev_warn(netdev, "cannot find free context\n"); | 1699 | netdev_warn(netdev, "cannot find free context\n"); |
1700 | |||
1701 | kfree(buf); | ||
1684 | ret = NETDEV_TX_BUSY; | 1702 | ret = NETDEV_TX_BUSY; |
1685 | goto releasebuf; | 1703 | goto freeurb; |
1686 | } | 1704 | } |
1687 | 1705 | ||
1688 | context->priv = priv; | 1706 | context->priv = priv; |
@@ -1719,16 +1737,12 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb, | |||
1719 | else | 1737 | else |
1720 | netdev_warn(netdev, "Failed tx_urb %d\n", err); | 1738 | netdev_warn(netdev, "Failed tx_urb %d\n", err); |
1721 | 1739 | ||
1722 | goto releasebuf; | 1740 | goto freeurb; |
1723 | } | 1741 | } |
1724 | 1742 | ||
1725 | usb_free_urb(urb); | 1743 | ret = NETDEV_TX_OK; |
1726 | |||
1727 | return NETDEV_TX_OK; | ||
1728 | 1744 | ||
1729 | releasebuf: | 1745 | freeurb: |
1730 | kfree(buf); | ||
1731 | nobufmem: | ||
1732 | usb_free_urb(urb); | 1746 | usb_free_urb(urb); |
1733 | return ret; | 1747 | return ret; |
1734 | } | 1748 | } |