Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

+52 -60
+52 -60
drivers/net/can/usb/gs_usb.c
··· 520 520 timestamp = le32_to_cpu(hf->classic_can_ts->timestamp_us); 521 521 522 522 gs_usb_skb_set_timestamp(dev, skb, timestamp); 523 - 524 - return; 525 523 } 526 524 527 525 static void gs_usb_receive_bulk_callback(struct urb *urb) 528 526 { 529 - struct gs_usb *usbcan = urb->context; 527 + struct gs_usb *parent = urb->context; 530 528 struct gs_can *dev; 531 529 struct net_device *netdev; 532 530 int rc; ··· 535 537 struct canfd_frame *cfd; 536 538 struct sk_buff *skb; 537 539 538 - BUG_ON(!usbcan); 540 + BUG_ON(!parent); 539 541 540 542 switch (urb->status) { 541 543 case 0: /* success */ ··· 552 554 if (hf->channel >= GS_MAX_INTF) 553 555 goto device_detach; 554 556 555 - dev = usbcan->canch[hf->channel]; 557 + dev = parent->canch[hf->channel]; 556 558 557 559 netdev = dev->netdev; 558 560 stats = &netdev->stats; ··· 565 567 566 568 if (hf->echo_id == -1) { /* normal rx */ 567 569 if (hf->flags & GS_CAN_FLAG_FD) { 568 - skb = alloc_canfd_skb(dev->netdev, &cfd); 570 + skb = alloc_canfd_skb(netdev, &cfd); 569 571 if (!skb) 570 572 return; 571 573 ··· 578 580 579 581 memcpy(cfd->data, hf->canfd->data, cfd->len); 580 582 } else { 581 - skb = alloc_can_skb(dev->netdev, &cf); 583 + skb = alloc_can_skb(netdev, &cf); 582 584 if (!skb) 583 585 return; 584 586 ··· 594 596 595 597 gs_usb_set_timestamp(dev, skb, hf); 596 598 597 - netdev->stats.rx_packets++; 598 - netdev->stats.rx_bytes += hf->can_dlc; 599 + stats->rx_packets++; 600 + stats->rx_bytes += hf->can_dlc; 599 601 600 602 netif_rx(skb); 601 603 } else { /* echo_id == hf->echo_id */ ··· 619 621 skb = dev->can.echo_skb[hf->echo_id]; 620 622 gs_usb_set_timestamp(dev, skb, hf); 621 623 622 - netdev->stats.tx_packets++; 623 - netdev->stats.tx_bytes += can_get_echo_skb(netdev, hf->echo_id, 624 - NULL); 624 + stats->tx_packets++; 625 + stats->tx_bytes += can_get_echo_skb(netdev, hf->echo_id, 626 + NULL); 625 627 626 628 gs_free_tx_context(txc); 627 629 ··· 631 633 } 632 634 633 635 if (hf->flags & GS_CAN_FLAG_OVERFLOW) { 636 + stats->rx_over_errors++; 637 + stats->rx_errors++; 638 + 634 639 skb = alloc_can_err_skb(netdev, &cf); 635 640 if (!skb) 636 641 goto resubmit_urb; ··· 641 640 cf->can_id |= CAN_ERR_CRTL; 642 641 cf->len = CAN_ERR_DLC; 643 642 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; 644 - stats->rx_over_errors++; 645 - stats->rx_errors++; 646 643 netif_rx(skb); 647 644 } 648 645 649 - resubmit_urb: 650 - usb_fill_bulk_urb(urb, usbcan->udev, 651 - usb_rcvbulkpipe(usbcan->udev, GS_USB_ENDPOINT_IN), 646 + resubmit_urb: 647 + usb_fill_bulk_urb(urb, parent->udev, 648 + usb_rcvbulkpipe(parent->udev, GS_USB_ENDPOINT_IN), 652 649 hf, dev->parent->hf_size_rx, 653 - gs_usb_receive_bulk_callback, usbcan); 650 + gs_usb_receive_bulk_callback, parent); 654 651 655 652 rc = usb_submit_urb(urb, GFP_ATOMIC); 656 653 657 654 /* USB failure take down all interfaces */ 658 655 if (rc == -ENODEV) { 659 - device_detach: 656 + device_detach: 660 657 for (rc = 0; rc < GS_MAX_INTF; rc++) { 661 - if (usbcan->canch[rc]) 662 - netif_device_detach(usbcan->canch[rc]->netdev); 658 + if (parent->canch[rc]) 659 + netif_device_detach(parent->canch[rc]->netdev); 663 660 } 664 661 } 665 662 } ··· 741 742 goto nomem_urb; 742 743 743 744 hf = kmalloc(dev->hf_size_tx, GFP_ATOMIC); 744 - if (!hf) { 745 - netdev_err(netdev, "No memory left for USB buffer\n"); 745 + if (!hf) 746 746 goto nomem_hf; 747 - } 748 747 749 748 idx = txc->echo_id; 750 749 ··· 815 818 816 819 return NETDEV_TX_OK; 817 820 818 - badidx: 821 + badidx: 819 822 kfree(hf); 820 - nomem_hf: 823 + nomem_hf: 821 824 usb_free_urb(urb); 822 825 823 - nomem_urb: 826 + nomem_urb: 824 827 gs_free_tx_context(txc); 825 828 dev_kfree_skb(skb); 826 829 stats->tx_dropped++; ··· 875 878 buf = kmalloc(dev->parent->hf_size_rx, 876 879 GFP_KERNEL); 877 880 if (!buf) { 878 - netdev_err(netdev, 879 - "No memory left for USB buffer\n"); 880 881 rc = -ENOMEM; 881 882 goto out_usb_free_urb; 882 883 } ··· 897 902 netif_device_detach(dev->netdev); 898 903 899 904 netdev_err(netdev, 900 - "usb_submit failed (err=%d)\n", rc); 905 + "usb_submit_urb() failed, error %pe\n", 906 + ERR_PTR(rc)); 901 907 902 908 goto out_usb_unanchor_urb; 903 909 } ··· 1029 1033 dev->can.state = CAN_STATE_STOPPED; 1030 1034 1031 1035 /* reset the device */ 1032 - rc = gs_cmd_reset(dev); 1033 - if (rc < 0) 1034 - netdev_warn(netdev, "Couldn't shutdown device (err=%d)", rc); 1036 + gs_cmd_reset(dev); 1035 1037 1036 1038 /* reset tx contexts */ 1037 1039 for (rc = 0; rc < GS_MAX_TX_URBS; rc++) { ··· 1348 1354 1349 1355 return dev; 1350 1356 1351 - out_free_candev: 1357 + out_free_candev: 1352 1358 free_candev(dev->netdev); 1353 1359 return ERR_PTR(rc); 1354 1360 } ··· 1356 1362 static void gs_destroy_candev(struct gs_can *dev) 1357 1363 { 1358 1364 unregister_candev(dev->netdev); 1359 - usb_kill_anchored_urbs(&dev->tx_submitted); 1360 1365 free_candev(dev->netdev); 1361 1366 } 1362 1367 ··· 1364 1371 { 1365 1372 struct usb_device *udev = interface_to_usbdev(intf); 1366 1373 struct gs_host_frame *hf; 1367 - struct gs_usb *dev; 1374 + struct gs_usb *parent; 1368 1375 struct gs_host_config hconf = { 1369 1376 .byte_order = cpu_to_le32(0x0000beef), 1370 1377 }; ··· 1407 1414 return -EINVAL; 1408 1415 } 1409 1416 1410 - dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1411 - if (!dev) 1417 + parent = kzalloc(sizeof(*parent), GFP_KERNEL); 1418 + if (!parent) 1412 1419 return -ENOMEM; 1413 1420 1414 - init_usb_anchor(&dev->rx_submitted); 1421 + init_usb_anchor(&parent->rx_submitted); 1415 1422 1416 - usb_set_intfdata(intf, dev); 1417 - dev->udev = udev; 1423 + usb_set_intfdata(intf, parent); 1424 + parent->udev = udev; 1418 1425 1419 1426 for (i = 0; i < icount; i++) { 1420 1427 unsigned int hf_size_rx = 0; 1421 1428 1422 - dev->canch[i] = gs_make_candev(i, intf, &dconf); 1423 - if (IS_ERR_OR_NULL(dev->canch[i])) { 1429 + parent->canch[i] = gs_make_candev(i, intf, &dconf); 1430 + if (IS_ERR_OR_NULL(parent->canch[i])) { 1424 1431 /* save error code to return later */ 1425 - rc = PTR_ERR(dev->canch[i]); 1432 + rc = PTR_ERR(parent->canch[i]); 1426 1433 1427 1434 /* on failure destroy previously created candevs */ 1428 1435 icount = i; 1429 1436 for (i = 0; i < icount; i++) 1430 - gs_destroy_candev(dev->canch[i]); 1437 + gs_destroy_candev(parent->canch[i]); 1431 1438 1432 - usb_kill_anchored_urbs(&dev->rx_submitted); 1433 - kfree(dev); 1439 + usb_kill_anchored_urbs(&parent->rx_submitted); 1440 + kfree(parent); 1434 1441 return rc; 1435 1442 } 1436 - dev->canch[i]->parent = dev; 1443 + parent->canch[i]->parent = parent; 1437 1444 1438 1445 /* set RX packet size based on FD and if hardware 1439 - * timestamps are supported. 1440 - */ 1441 - if (dev->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) { 1442 - if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1446 + * timestamps are supported. 1447 + */ 1448 + if (parent->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) { 1449 + if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1443 1450 hf_size_rx = struct_size(hf, canfd_ts, 1); 1444 1451 else 1445 1452 hf_size_rx = struct_size(hf, canfd, 1); 1446 1453 } else { 1447 - if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1454 + if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1448 1455 hf_size_rx = struct_size(hf, classic_can_ts, 1); 1449 1456 else 1450 1457 hf_size_rx = struct_size(hf, classic_can, 1); 1451 1458 } 1452 - dev->hf_size_rx = max(dev->hf_size_rx, hf_size_rx); 1459 + parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx); 1453 1460 } 1454 1461 1455 1462 return 0; ··· 1457 1464 1458 1465 static void gs_usb_disconnect(struct usb_interface *intf) 1459 1466 { 1460 - struct gs_usb *dev = usb_get_intfdata(intf); 1467 + struct gs_usb *parent = usb_get_intfdata(intf); 1461 1468 unsigned int i; 1462 1469 1463 1470 usb_set_intfdata(intf, NULL); 1464 1471 1465 - if (!dev) { 1472 + if (!parent) { 1466 1473 dev_err(&intf->dev, "Disconnect (nodata)\n"); 1467 1474 return; 1468 1475 } 1469 1476 1470 1477 for (i = 0; i < GS_MAX_INTF; i++) 1471 - if (dev->canch[i]) 1472 - gs_destroy_candev(dev->canch[i]); 1478 + if (parent->canch[i]) 1479 + gs_destroy_candev(parent->canch[i]); 1473 1480 1474 - usb_kill_anchored_urbs(&dev->rx_submitted); 1475 - kfree(dev); 1481 + kfree(parent); 1476 1482 } 1477 1483 1478 1484 static const struct usb_device_id gs_usb_table[] = {