Skip to content

Commit 412fbb8

Browse files
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>
2 parents 07382e6 + d4cfb83 commit 412fbb8

File tree

1 file changed

+52
-60
lines changed

1 file changed

+52
-60
lines changed

drivers/net/can/usb/gs_usb.c

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,11 @@ static void gs_usb_set_timestamp(struct gs_can *dev, struct sk_buff *skb,
520520
timestamp = le32_to_cpu(hf->classic_can_ts->timestamp_us);
521521

522522
gs_usb_skb_set_timestamp(dev, skb, timestamp);
523-
524-
return;
525523
}
526524

527525
static void gs_usb_receive_bulk_callback(struct urb *urb)
528526
{
529-
struct gs_usb *usbcan = urb->context;
527+
struct gs_usb *parent = urb->context;
530528
struct gs_can *dev;
531529
struct net_device *netdev;
532530
int rc;
@@ -537,7 +535,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
537535
struct canfd_frame *cfd;
538536
struct sk_buff *skb;
539537

540-
BUG_ON(!usbcan);
538+
BUG_ON(!parent);
541539

542540
switch (urb->status) {
543541
case 0: /* success */
@@ -554,7 +552,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
554552
if (hf->channel >= GS_MAX_INTF)
555553
goto device_detach;
556554

557-
dev = usbcan->canch[hf->channel];
555+
dev = parent->canch[hf->channel];
558556

559557
netdev = dev->netdev;
560558
stats = &netdev->stats;
@@ -567,7 +565,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
567565

568566
if (hf->echo_id == -1) { /* normal rx */
569567
if (hf->flags & GS_CAN_FLAG_FD) {
570-
skb = alloc_canfd_skb(dev->netdev, &cfd);
568+
skb = alloc_canfd_skb(netdev, &cfd);
571569
if (!skb)
572570
return;
573571

@@ -580,7 +578,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
580578

581579
memcpy(cfd->data, hf->canfd->data, cfd->len);
582580
} else {
583-
skb = alloc_can_skb(dev->netdev, &cf);
581+
skb = alloc_can_skb(netdev, &cf);
584582
if (!skb)
585583
return;
586584

@@ -596,8 +594,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
596594

597595
gs_usb_set_timestamp(dev, skb, hf);
598596

599-
netdev->stats.rx_packets++;
600-
netdev->stats.rx_bytes += hf->can_dlc;
597+
stats->rx_packets++;
598+
stats->rx_bytes += hf->can_dlc;
601599

602600
netif_rx(skb);
603601
} else { /* echo_id == hf->echo_id */
@@ -621,9 +619,9 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
621619
skb = dev->can.echo_skb[hf->echo_id];
622620
gs_usb_set_timestamp(dev, skb, hf);
623621

624-
netdev->stats.tx_packets++;
625-
netdev->stats.tx_bytes += can_get_echo_skb(netdev, hf->echo_id,
626-
NULL);
622+
stats->tx_packets++;
623+
stats->tx_bytes += can_get_echo_skb(netdev, hf->echo_id,
624+
NULL);
627625

628626
gs_free_tx_context(txc);
629627

@@ -633,32 +631,33 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
633631
}
634632

635633
if (hf->flags & GS_CAN_FLAG_OVERFLOW) {
634+
stats->rx_over_errors++;
635+
stats->rx_errors++;
636+
636637
skb = alloc_can_err_skb(netdev, &cf);
637638
if (!skb)
638639
goto resubmit_urb;
639640

640641
cf->can_id |= CAN_ERR_CRTL;
641642
cf->len = CAN_ERR_DLC;
642643
cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
643-
stats->rx_over_errors++;
644-
stats->rx_errors++;
645644
netif_rx(skb);
646645
}
647646

648-
resubmit_urb:
649-
usb_fill_bulk_urb(urb, usbcan->udev,
650-
usb_rcvbulkpipe(usbcan->udev, GS_USB_ENDPOINT_IN),
647+
resubmit_urb:
648+
usb_fill_bulk_urb(urb, parent->udev,
649+
usb_rcvbulkpipe(parent->udev, GS_USB_ENDPOINT_IN),
651650
hf, dev->parent->hf_size_rx,
652-
gs_usb_receive_bulk_callback, usbcan);
651+
gs_usb_receive_bulk_callback, parent);
653652

654653
rc = usb_submit_urb(urb, GFP_ATOMIC);
655654

656655
/* USB failure take down all interfaces */
657656
if (rc == -ENODEV) {
658-
device_detach:
657+
device_detach:
659658
for (rc = 0; rc < GS_MAX_INTF; rc++) {
660-
if (usbcan->canch[rc])
661-
netif_device_detach(usbcan->canch[rc]->netdev);
659+
if (parent->canch[rc])
660+
netif_device_detach(parent->canch[rc]->netdev);
662661
}
663662
}
664663
}
@@ -742,10 +741,8 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
742741
goto nomem_urb;
743742

744743
hf = kmalloc(dev->hf_size_tx, GFP_ATOMIC);
745-
if (!hf) {
746-
netdev_err(netdev, "No memory left for USB buffer\n");
744+
if (!hf)
747745
goto nomem_hf;
748-
}
749746

750747
idx = txc->echo_id;
751748

@@ -818,12 +815,12 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
818815

819816
return NETDEV_TX_OK;
820817

821-
badidx:
818+
badidx:
822819
kfree(hf);
823-
nomem_hf:
820+
nomem_hf:
824821
usb_free_urb(urb);
825822

826-
nomem_urb:
823+
nomem_urb:
827824
gs_free_tx_context(txc);
828825
dev_kfree_skb(skb);
829826
stats->tx_dropped++;
@@ -878,8 +875,6 @@ static int gs_can_open(struct net_device *netdev)
878875
buf = kmalloc(dev->parent->hf_size_rx,
879876
GFP_KERNEL);
880877
if (!buf) {
881-
netdev_err(netdev,
882-
"No memory left for USB buffer\n");
883878
rc = -ENOMEM;
884879
goto out_usb_free_urb;
885880
}
@@ -902,7 +897,8 @@ static int gs_can_open(struct net_device *netdev)
902897
netif_device_detach(dev->netdev);
903898

904899
netdev_err(netdev,
905-
"usb_submit failed (err=%d)\n", rc);
900+
"usb_submit_urb() failed, error %pe\n",
901+
ERR_PTR(rc));
906902

907903
goto out_usb_unanchor_urb;
908904
}
@@ -1033,9 +1029,7 @@ static int gs_can_close(struct net_device *netdev)
10331029
dev->can.state = CAN_STATE_STOPPED;
10341030

10351031
/* reset the device */
1036-
rc = gs_cmd_reset(dev);
1037-
if (rc < 0)
1038-
netdev_warn(netdev, "Couldn't shutdown device (err=%d)", rc);
1032+
gs_cmd_reset(dev);
10391033

10401034
/* reset tx contexts */
10411035
for (rc = 0; rc < GS_MAX_TX_URBS; rc++) {
@@ -1354,15 +1348,14 @@ static struct gs_can *gs_make_candev(unsigned int channel,
13541348

13551349
return dev;
13561350

1357-
out_free_candev:
1351+
out_free_candev:
13581352
free_candev(dev->netdev);
13591353
return ERR_PTR(rc);
13601354
}
13611355

13621356
static void gs_destroy_candev(struct gs_can *dev)
13631357
{
13641358
unregister_candev(dev->netdev);
1365-
usb_kill_anchored_urbs(&dev->tx_submitted);
13661359
free_candev(dev->netdev);
13671360
}
13681361

@@ -1371,7 +1364,7 @@ static int gs_usb_probe(struct usb_interface *intf,
13711364
{
13721365
struct usb_device *udev = interface_to_usbdev(intf);
13731366
struct gs_host_frame *hf;
1374-
struct gs_usb *dev;
1367+
struct gs_usb *parent;
13751368
struct gs_host_config hconf = {
13761369
.byte_order = cpu_to_le32(0x0000beef),
13771370
};
@@ -1414,72 +1407,71 @@ static int gs_usb_probe(struct usb_interface *intf,
14141407
return -EINVAL;
14151408
}
14161409

1417-
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1418-
if (!dev)
1410+
parent = kzalloc(sizeof(*parent), GFP_KERNEL);
1411+
if (!parent)
14191412
return -ENOMEM;
14201413

1421-
init_usb_anchor(&dev->rx_submitted);
1414+
init_usb_anchor(&parent->rx_submitted);
14221415

1423-
usb_set_intfdata(intf, dev);
1424-
dev->udev = udev;
1416+
usb_set_intfdata(intf, parent);
1417+
parent->udev = udev;
14251418

14261419
for (i = 0; i < icount; i++) {
14271420
unsigned int hf_size_rx = 0;
14281421

1429-
dev->canch[i] = gs_make_candev(i, intf, &dconf);
1430-
if (IS_ERR_OR_NULL(dev->canch[i])) {
1422+
parent->canch[i] = gs_make_candev(i, intf, &dconf);
1423+
if (IS_ERR_OR_NULL(parent->canch[i])) {
14311424
/* save error code to return later */
1432-
rc = PTR_ERR(dev->canch[i]);
1425+
rc = PTR_ERR(parent->canch[i]);
14331426

14341427
/* on failure destroy previously created candevs */
14351428
icount = i;
14361429
for (i = 0; i < icount; i++)
1437-
gs_destroy_candev(dev->canch[i]);
1430+
gs_destroy_candev(parent->canch[i]);
14381431

1439-
usb_kill_anchored_urbs(&dev->rx_submitted);
1440-
kfree(dev);
1432+
usb_kill_anchored_urbs(&parent->rx_submitted);
1433+
kfree(parent);
14411434
return rc;
14421435
}
1443-
dev->canch[i]->parent = dev;
1436+
parent->canch[i]->parent = parent;
14441437

14451438
/* set RX packet size based on FD and if hardware
1446-
* timestamps are supported.
1447-
*/
1448-
if (dev->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) {
1449-
if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1439+
* timestamps are supported.
1440+
*/
1441+
if (parent->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) {
1442+
if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
14501443
hf_size_rx = struct_size(hf, canfd_ts, 1);
14511444
else
14521445
hf_size_rx = struct_size(hf, canfd, 1);
14531446
} else {
1454-
if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1447+
if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
14551448
hf_size_rx = struct_size(hf, classic_can_ts, 1);
14561449
else
14571450
hf_size_rx = struct_size(hf, classic_can, 1);
14581451
}
1459-
dev->hf_size_rx = max(dev->hf_size_rx, hf_size_rx);
1452+
parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx);
14601453
}
14611454

14621455
return 0;
14631456
}
14641457

14651458
static void gs_usb_disconnect(struct usb_interface *intf)
14661459
{
1467-
struct gs_usb *dev = usb_get_intfdata(intf);
1460+
struct gs_usb *parent = usb_get_intfdata(intf);
14681461
unsigned int i;
14691462

14701463
usb_set_intfdata(intf, NULL);
14711464

1472-
if (!dev) {
1465+
if (!parent) {
14731466
dev_err(&intf->dev, "Disconnect (nodata)\n");
14741467
return;
14751468
}
14761469

14771470
for (i = 0; i < GS_MAX_INTF; i++)
1478-
if (dev->canch[i])
1479-
gs_destroy_candev(dev->canch[i]);
1471+
if (parent->canch[i])
1472+
gs_destroy_candev(parent->canch[i]);
14801473

1481-
usb_kill_anchored_urbs(&dev->rx_submitted);
1482-
kfree(dev);
1474+
kfree(parent);
14831475
}
14841476

14851477
static const struct usb_device_id gs_usb_table[] = {

0 commit comments

Comments
 (0)