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

can: peak_usb: fix hwtstamp assignment

The skb->tstamp is set to the hardware timestamp when available in the USB
urb message. This leads to user visible timestamps which contain the 'uptime'
of the USB adapter - and not the usual system generated timestamp.

Fix this wrong assignment by applying the available hardware timestamp to the
skb_shared_hwtstamps data structure - which is intended for this purpose.

Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Oliver Hartkopp and committed by
Marc Kleine-Budde
c9faaa09 194d9831

+12 -4
+6 -2
drivers/net/can/usb/peak_usb/pcan_usb.c
··· 519 519 mc->pdev->dev.can.state = new_state; 520 520 521 521 if (status_len & PCAN_USB_STATUSLEN_TIMESTAMP) { 522 + struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb); 523 + 522 524 peak_usb_get_ts_tv(&mc->pdev->time_ref, mc->ts16, &tv); 523 - skb->tstamp = timeval_to_ktime(tv); 525 + hwts->hwtstamp = timeval_to_ktime(tv); 524 526 } 525 527 526 528 netif_rx(skb); ··· 607 605 struct sk_buff *skb; 608 606 struct can_frame *cf; 609 607 struct timeval tv; 608 + struct skb_shared_hwtstamps *hwts; 610 609 611 610 skb = alloc_can_skb(mc->netdev, &cf); 612 611 if (!skb) ··· 655 652 656 653 /* convert timestamp into kernel time */ 657 654 peak_usb_get_ts_tv(&mc->pdev->time_ref, mc->ts16, &tv); 658 - skb->tstamp = timeval_to_ktime(tv); 655 + hwts = skb_hwtstamps(skb); 656 + hwts->hwtstamp = timeval_to_ktime(tv); 659 657 660 658 /* push the skb */ 661 659 netif_rx(skb);
+6 -2
drivers/net/can/usb/peak_usb/pcan_usb_pro.c
··· 532 532 struct can_frame *can_frame; 533 533 struct sk_buff *skb; 534 534 struct timeval tv; 535 + struct skb_shared_hwtstamps *hwts; 535 536 536 537 skb = alloc_can_skb(netdev, &can_frame); 537 538 if (!skb) ··· 550 549 memcpy(can_frame->data, rx->data, can_frame->can_dlc); 551 550 552 551 peak_usb_get_ts_tv(&usb_if->time_ref, le32_to_cpu(rx->ts32), &tv); 553 - skb->tstamp = timeval_to_ktime(tv); 552 + hwts = skb_hwtstamps(skb); 553 + hwts->hwtstamp = timeval_to_ktime(tv); 554 554 555 555 netif_rx(skb); 556 556 netdev->stats.rx_packets++; ··· 572 570 u8 err_mask = 0; 573 571 struct sk_buff *skb; 574 572 struct timeval tv; 573 + struct skb_shared_hwtstamps *hwts; 575 574 576 575 /* nothing should be sent while in BUS_OFF state */ 577 576 if (dev->can.state == CAN_STATE_BUS_OFF) ··· 667 664 dev->can.state = new_state; 668 665 669 666 peak_usb_get_ts_tv(&usb_if->time_ref, le32_to_cpu(er->ts32), &tv); 670 - skb->tstamp = timeval_to_ktime(tv); 667 + hwts = skb_hwtstamps(skb); 668 + hwts->hwtstamp = timeval_to_ktime(tv); 671 669 netif_rx(skb); 672 670 netdev->stats.rx_packets++; 673 671 netdev->stats.rx_bytes += can_frame->can_dlc;