Commit 412fbb84 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

Merge patch series "can: gs_usb-cleanups: various clenaups"

Marc Kleine-Budde <mkl@pengutronix.de> says:

This is a cleanup series of the gs_usb driver. Align the driver more
to the kernel coding style, make use of locally defined variables,
clean up printouts in various error paths, remove some not needed
usb_kill_anchored_urbs() from the shut down paths.

Link: https://lore.kernel.org/all/20230718-gs_usb-cleanups-v1-0-c3b9154ec605@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parents 07382e6b d4cfb83d
...@@ -520,13 +520,11 @@ static void gs_usb_set_timestamp(struct gs_can *dev, struct sk_buff *skb, ...@@ -520,13 +520,11 @@ static void gs_usb_set_timestamp(struct gs_can *dev, struct sk_buff *skb,
timestamp = le32_to_cpu(hf->classic_can_ts->timestamp_us); timestamp = le32_to_cpu(hf->classic_can_ts->timestamp_us);
gs_usb_skb_set_timestamp(dev, skb, timestamp); gs_usb_skb_set_timestamp(dev, skb, timestamp);
return;
} }
static void gs_usb_receive_bulk_callback(struct urb *urb) static void gs_usb_receive_bulk_callback(struct urb *urb)
{ {
struct gs_usb *usbcan = urb->context; struct gs_usb *parent = urb->context;
struct gs_can *dev; struct gs_can *dev;
struct net_device *netdev; struct net_device *netdev;
int rc; int rc;
...@@ -537,7 +535,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -537,7 +535,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
struct canfd_frame *cfd; struct canfd_frame *cfd;
struct sk_buff *skb; struct sk_buff *skb;
BUG_ON(!usbcan); BUG_ON(!parent);
switch (urb->status) { switch (urb->status) {
case 0: /* success */ case 0: /* success */
...@@ -554,7 +552,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -554,7 +552,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
if (hf->channel >= GS_MAX_INTF) if (hf->channel >= GS_MAX_INTF)
goto device_detach; goto device_detach;
dev = usbcan->canch[hf->channel]; dev = parent->canch[hf->channel];
netdev = dev->netdev; netdev = dev->netdev;
stats = &netdev->stats; stats = &netdev->stats;
...@@ -567,7 +565,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -567,7 +565,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
if (hf->echo_id == -1) { /* normal rx */ if (hf->echo_id == -1) { /* normal rx */
if (hf->flags & GS_CAN_FLAG_FD) { if (hf->flags & GS_CAN_FLAG_FD) {
skb = alloc_canfd_skb(dev->netdev, &cfd); skb = alloc_canfd_skb(netdev, &cfd);
if (!skb) if (!skb)
return; return;
...@@ -580,7 +578,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -580,7 +578,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
memcpy(cfd->data, hf->canfd->data, cfd->len); memcpy(cfd->data, hf->canfd->data, cfd->len);
} else { } else {
skb = alloc_can_skb(dev->netdev, &cf); skb = alloc_can_skb(netdev, &cf);
if (!skb) if (!skb)
return; return;
...@@ -596,8 +594,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -596,8 +594,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
gs_usb_set_timestamp(dev, skb, hf); gs_usb_set_timestamp(dev, skb, hf);
netdev->stats.rx_packets++; stats->rx_packets++;
netdev->stats.rx_bytes += hf->can_dlc; stats->rx_bytes += hf->can_dlc;
netif_rx(skb); netif_rx(skb);
} else { /* echo_id == hf->echo_id */ } else { /* echo_id == hf->echo_id */
...@@ -621,9 +619,9 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -621,9 +619,9 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
skb = dev->can.echo_skb[hf->echo_id]; skb = dev->can.echo_skb[hf->echo_id];
gs_usb_set_timestamp(dev, skb, hf); gs_usb_set_timestamp(dev, skb, hf);
netdev->stats.tx_packets++; stats->tx_packets++;
netdev->stats.tx_bytes += can_get_echo_skb(netdev, hf->echo_id, stats->tx_bytes += can_get_echo_skb(netdev, hf->echo_id,
NULL); NULL);
gs_free_tx_context(txc); gs_free_tx_context(txc);
...@@ -633,6 +631,9 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -633,6 +631,9 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
} }
if (hf->flags & GS_CAN_FLAG_OVERFLOW) { if (hf->flags & GS_CAN_FLAG_OVERFLOW) {
stats->rx_over_errors++;
stats->rx_errors++;
skb = alloc_can_err_skb(netdev, &cf); skb = alloc_can_err_skb(netdev, &cf);
if (!skb) if (!skb)
goto resubmit_urb; goto resubmit_urb;
...@@ -640,25 +641,23 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) ...@@ -640,25 +641,23 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
cf->can_id |= CAN_ERR_CRTL; cf->can_id |= CAN_ERR_CRTL;
cf->len = CAN_ERR_DLC; cf->len = CAN_ERR_DLC;
cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
stats->rx_over_errors++;
stats->rx_errors++;
netif_rx(skb); netif_rx(skb);
} }
resubmit_urb: resubmit_urb:
usb_fill_bulk_urb(urb, usbcan->udev, usb_fill_bulk_urb(urb, parent->udev,
usb_rcvbulkpipe(usbcan->udev, GS_USB_ENDPOINT_IN), usb_rcvbulkpipe(parent->udev, GS_USB_ENDPOINT_IN),
hf, dev->parent->hf_size_rx, hf, dev->parent->hf_size_rx,
gs_usb_receive_bulk_callback, usbcan); gs_usb_receive_bulk_callback, parent);
rc = usb_submit_urb(urb, GFP_ATOMIC); rc = usb_submit_urb(urb, GFP_ATOMIC);
/* USB failure take down all interfaces */ /* USB failure take down all interfaces */
if (rc == -ENODEV) { if (rc == -ENODEV) {
device_detach: device_detach:
for (rc = 0; rc < GS_MAX_INTF; rc++) { for (rc = 0; rc < GS_MAX_INTF; rc++) {
if (usbcan->canch[rc]) if (parent->canch[rc])
netif_device_detach(usbcan->canch[rc]->netdev); netif_device_detach(parent->canch[rc]->netdev);
} }
} }
} }
...@@ -742,10 +741,8 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, ...@@ -742,10 +741,8 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
goto nomem_urb; goto nomem_urb;
hf = kmalloc(dev->hf_size_tx, GFP_ATOMIC); hf = kmalloc(dev->hf_size_tx, GFP_ATOMIC);
if (!hf) { if (!hf)
netdev_err(netdev, "No memory left for USB buffer\n");
goto nomem_hf; goto nomem_hf;
}
idx = txc->echo_id; idx = txc->echo_id;
...@@ -818,12 +815,12 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, ...@@ -818,12 +815,12 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
return NETDEV_TX_OK; return NETDEV_TX_OK;
badidx: badidx:
kfree(hf); kfree(hf);
nomem_hf: nomem_hf:
usb_free_urb(urb); usb_free_urb(urb);
nomem_urb: nomem_urb:
gs_free_tx_context(txc); gs_free_tx_context(txc);
dev_kfree_skb(skb); dev_kfree_skb(skb);
stats->tx_dropped++; stats->tx_dropped++;
...@@ -878,8 +875,6 @@ static int gs_can_open(struct net_device *netdev) ...@@ -878,8 +875,6 @@ static int gs_can_open(struct net_device *netdev)
buf = kmalloc(dev->parent->hf_size_rx, buf = kmalloc(dev->parent->hf_size_rx,
GFP_KERNEL); GFP_KERNEL);
if (!buf) { if (!buf) {
netdev_err(netdev,
"No memory left for USB buffer\n");
rc = -ENOMEM; rc = -ENOMEM;
goto out_usb_free_urb; goto out_usb_free_urb;
} }
...@@ -902,7 +897,8 @@ static int gs_can_open(struct net_device *netdev) ...@@ -902,7 +897,8 @@ static int gs_can_open(struct net_device *netdev)
netif_device_detach(dev->netdev); netif_device_detach(dev->netdev);
netdev_err(netdev, netdev_err(netdev,
"usb_submit failed (err=%d)\n", rc); "usb_submit_urb() failed, error %pe\n",
ERR_PTR(rc));
goto out_usb_unanchor_urb; goto out_usb_unanchor_urb;
} }
...@@ -1033,9 +1029,7 @@ static int gs_can_close(struct net_device *netdev) ...@@ -1033,9 +1029,7 @@ static int gs_can_close(struct net_device *netdev)
dev->can.state = CAN_STATE_STOPPED; dev->can.state = CAN_STATE_STOPPED;
/* reset the device */ /* reset the device */
rc = gs_cmd_reset(dev); gs_cmd_reset(dev);
if (rc < 0)
netdev_warn(netdev, "Couldn't shutdown device (err=%d)", rc);
/* reset tx contexts */ /* reset tx contexts */
for (rc = 0; rc < GS_MAX_TX_URBS; rc++) { for (rc = 0; rc < GS_MAX_TX_URBS; rc++) {
...@@ -1354,7 +1348,7 @@ static struct gs_can *gs_make_candev(unsigned int channel, ...@@ -1354,7 +1348,7 @@ static struct gs_can *gs_make_candev(unsigned int channel,
return dev; return dev;
out_free_candev: out_free_candev:
free_candev(dev->netdev); free_candev(dev->netdev);
return ERR_PTR(rc); return ERR_PTR(rc);
} }
...@@ -1362,7 +1356,6 @@ static struct gs_can *gs_make_candev(unsigned int channel, ...@@ -1362,7 +1356,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
static void gs_destroy_candev(struct gs_can *dev) static void gs_destroy_candev(struct gs_can *dev)
{ {
unregister_candev(dev->netdev); unregister_candev(dev->netdev);
usb_kill_anchored_urbs(&dev->tx_submitted);
free_candev(dev->netdev); free_candev(dev->netdev);
} }
...@@ -1371,7 +1364,7 @@ static int gs_usb_probe(struct usb_interface *intf, ...@@ -1371,7 +1364,7 @@ static int gs_usb_probe(struct usb_interface *intf,
{ {
struct usb_device *udev = interface_to_usbdev(intf); struct usb_device *udev = interface_to_usbdev(intf);
struct gs_host_frame *hf; struct gs_host_frame *hf;
struct gs_usb *dev; struct gs_usb *parent;
struct gs_host_config hconf = { struct gs_host_config hconf = {
.byte_order = cpu_to_le32(0x0000beef), .byte_order = cpu_to_le32(0x0000beef),
}; };
...@@ -1414,49 +1407,49 @@ static int gs_usb_probe(struct usb_interface *intf, ...@@ -1414,49 +1407,49 @@ static int gs_usb_probe(struct usb_interface *intf,
return -EINVAL; return -EINVAL;
} }
dev = kzalloc(sizeof(*dev), GFP_KERNEL); parent = kzalloc(sizeof(*parent), GFP_KERNEL);
if (!dev) if (!parent)
return -ENOMEM; return -ENOMEM;
init_usb_anchor(&dev->rx_submitted); init_usb_anchor(&parent->rx_submitted);
usb_set_intfdata(intf, dev); usb_set_intfdata(intf, parent);
dev->udev = udev; parent->udev = udev;
for (i = 0; i < icount; i++) { for (i = 0; i < icount; i++) {
unsigned int hf_size_rx = 0; unsigned int hf_size_rx = 0;
dev->canch[i] = gs_make_candev(i, intf, &dconf); parent->canch[i] = gs_make_candev(i, intf, &dconf);
if (IS_ERR_OR_NULL(dev->canch[i])) { if (IS_ERR_OR_NULL(parent->canch[i])) {
/* save error code to return later */ /* save error code to return later */
rc = PTR_ERR(dev->canch[i]); rc = PTR_ERR(parent->canch[i]);
/* on failure destroy previously created candevs */ /* on failure destroy previously created candevs */
icount = i; icount = i;
for (i = 0; i < icount; i++) for (i = 0; i < icount; i++)
gs_destroy_candev(dev->canch[i]); gs_destroy_candev(parent->canch[i]);
usb_kill_anchored_urbs(&dev->rx_submitted); usb_kill_anchored_urbs(&parent->rx_submitted);
kfree(dev); kfree(parent);
return rc; return rc;
} }
dev->canch[i]->parent = dev; parent->canch[i]->parent = parent;
/* set RX packet size based on FD and if hardware /* set RX packet size based on FD and if hardware
* timestamps are supported. * timestamps are supported.
*/ */
if (dev->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) { if (parent->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) {
if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
hf_size_rx = struct_size(hf, canfd_ts, 1); hf_size_rx = struct_size(hf, canfd_ts, 1);
else else
hf_size_rx = struct_size(hf, canfd, 1); hf_size_rx = struct_size(hf, canfd, 1);
} else { } else {
if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
hf_size_rx = struct_size(hf, classic_can_ts, 1); hf_size_rx = struct_size(hf, classic_can_ts, 1);
else else
hf_size_rx = struct_size(hf, classic_can, 1); hf_size_rx = struct_size(hf, classic_can, 1);
} }
dev->hf_size_rx = max(dev->hf_size_rx, hf_size_rx); parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx);
} }
return 0; return 0;
...@@ -1464,22 +1457,21 @@ static int gs_usb_probe(struct usb_interface *intf, ...@@ -1464,22 +1457,21 @@ static int gs_usb_probe(struct usb_interface *intf,
static void gs_usb_disconnect(struct usb_interface *intf) static void gs_usb_disconnect(struct usb_interface *intf)
{ {
struct gs_usb *dev = usb_get_intfdata(intf); struct gs_usb *parent = usb_get_intfdata(intf);
unsigned int i; unsigned int i;
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
if (!dev) { if (!parent) {
dev_err(&intf->dev, "Disconnect (nodata)\n"); dev_err(&intf->dev, "Disconnect (nodata)\n");
return; return;
} }
for (i = 0; i < GS_MAX_INTF; i++) for (i = 0; i < GS_MAX_INTF; i++)
if (dev->canch[i]) if (parent->canch[i])
gs_destroy_candev(dev->canch[i]); gs_destroy_candev(parent->canch[i]);
usb_kill_anchored_urbs(&dev->rx_submitted); kfree(parent);
kfree(dev);
} }
static const struct usb_device_id gs_usb_table[] = { static const struct usb_device_id gs_usb_table[] = {
......
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