Skip to content

Commit

Permalink
can: peak_usb: remove some 'struct timeval' users
Browse files Browse the repository at this point in the history
We want to remove 'struct timeval' and related interfaces since this is
generally not safe for use beyond 2038.

For peak_usb, we can simplify the internal interface by using ktime_t
directly. This should not change any behavior, but it avoids a few
conversions.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Arnd Bergmann authored and Marc Kleine-Budde committed Dec 1, 2017
1 parent 201c78e commit d5888a1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
9 changes: 3 additions & 6 deletions drivers/net/can/usb/peak_usb/pcan_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
{
struct sk_buff *skb;
struct can_frame *cf;
struct timeval tv;
enum can_state new_state;

/* ignore this error until 1st ts received */
Expand Down Expand Up @@ -525,8 +524,8 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
if (status_len & PCAN_USB_STATUSLEN_TIMESTAMP) {
struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);

peak_usb_get_ts_tv(&mc->pdev->time_ref, mc->ts16, &tv);
hwts->hwtstamp = timeval_to_ktime(tv);
peak_usb_get_ts_time(&mc->pdev->time_ref, mc->ts16,
&hwts->hwtstamp);
}

mc->netdev->stats.rx_packets++;
Expand Down Expand Up @@ -610,7 +609,6 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
u8 rec_len = status_len & PCAN_USB_STATUSLEN_DLC;
struct sk_buff *skb;
struct can_frame *cf;
struct timeval tv;
struct skb_shared_hwtstamps *hwts;

skb = alloc_can_skb(mc->netdev, &cf);
Expand Down Expand Up @@ -658,9 +656,8 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
}

/* convert timestamp into kernel time */
peak_usb_get_ts_tv(&mc->pdev->time_ref, mc->ts16, &tv);
hwts = skb_hwtstamps(skb);
hwts->hwtstamp = timeval_to_ktime(tv);
peak_usb_get_ts_time(&mc->pdev->time_ref, mc->ts16, &hwts->hwtstamp);

/* update statistics */
mc->netdev->stats.rx_packets++;
Expand Down
15 changes: 7 additions & 8 deletions drivers/net/can/usb/peak_usb/pcan_usb_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ void peak_usb_set_ts_now(struct peak_time_ref *time_ref, u32 ts_now)
/*
* compute timeval according to current ts and time_ref data
*/
void peak_usb_get_ts_tv(struct peak_time_ref *time_ref, u32 ts,
struct timeval *tv)
void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)
{
/* protect from getting timeval before setting now */
if (time_ref->tv_host.tv_sec > 0) {
struct timeval tv;
u64 delta_us;

delta_us = ts - time_ref->ts_dev_2;
Expand All @@ -164,10 +164,11 @@ void peak_usb_get_ts_tv(struct peak_time_ref *time_ref, u32 ts,
delta_us *= time_ref->adapter->us_per_ts_scale;
delta_us >>= time_ref->adapter->us_per_ts_shift;

*tv = time_ref->tv_host_0;
peak_usb_add_us(tv, (u32)delta_us);
tv = time_ref->tv_host_0;
peak_usb_add_us(&tv, (u32)delta_us);
*time = timeval_to_ktime(tv);
} else {
*tv = ktime_to_timeval(ktime_get());
*time = ktime_get();
}
}

Expand All @@ -178,10 +179,8 @@ int peak_usb_netif_rx(struct sk_buff *skb,
struct peak_time_ref *time_ref, u32 ts_low, u32 ts_high)
{
struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
struct timeval tv;

peak_usb_get_ts_tv(time_ref, ts_low, &tv);
hwts->hwtstamp = timeval_to_ktime(tv);
peak_usb_get_ts_time(time_ref, ts_low, &hwts->hwtstamp);

return netif_rx(skb);
}
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/can/usb/peak_usb/pcan_usb_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ void peak_usb_init_time_ref(struct peak_time_ref *time_ref,
const struct peak_usb_adapter *adapter);
void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now);
void peak_usb_set_ts_now(struct peak_time_ref *time_ref, u32 ts_now);
void peak_usb_get_ts_tv(struct peak_time_ref *time_ref, u32 ts,
struct timeval *tv);
void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *tv);
int peak_usb_netif_rx(struct sk_buff *skb,
struct peak_time_ref *time_ref, u32 ts_low, u32 ts_high);
void peak_usb_async_complete(struct urb *urb);
Expand Down
9 changes: 3 additions & 6 deletions drivers/net/can/usb/peak_usb/pcan_usb_pro.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,
struct net_device *netdev = dev->netdev;
struct can_frame *can_frame;
struct sk_buff *skb;
struct timeval tv;
struct skb_shared_hwtstamps *hwts;

skb = alloc_can_skb(netdev, &can_frame);
Expand All @@ -549,9 +548,9 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,
else
memcpy(can_frame->data, rx->data, can_frame->can_dlc);

peak_usb_get_ts_tv(&usb_if->time_ref, le32_to_cpu(rx->ts32), &tv);
hwts = skb_hwtstamps(skb);
hwts->hwtstamp = timeval_to_ktime(tv);
peak_usb_get_ts_time(&usb_if->time_ref, le32_to_cpu(rx->ts32),
&hwts->hwtstamp);

netdev->stats.rx_packets++;
netdev->stats.rx_bytes += can_frame->can_dlc;
Expand All @@ -571,7 +570,6 @@ static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if,
enum can_state new_state = CAN_STATE_ERROR_ACTIVE;
u8 err_mask = 0;
struct sk_buff *skb;
struct timeval tv;
struct skb_shared_hwtstamps *hwts;

/* nothing should be sent while in BUS_OFF state */
Expand Down Expand Up @@ -667,9 +665,8 @@ static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if,

dev->can.state = new_state;

peak_usb_get_ts_tv(&usb_if->time_ref, le32_to_cpu(er->ts32), &tv);
hwts = skb_hwtstamps(skb);
hwts->hwtstamp = timeval_to_ktime(tv);
peak_usb_get_ts_time(&usb_if->time_ref, le32_to_cpu(er->ts32), &hwts->hwtstamp);
netdev->stats.rx_packets++;
netdev->stats.rx_bytes += can_frame->can_dlc;
netif_rx(skb);
Expand Down

0 comments on commit d5888a1

Please sign in to comment.