From patchwork Fri Nov 3 16:31:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 117950 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3667628qgn; Fri, 3 Nov 2017 09:33:06 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R8O98fq9UgX4N9GjvY3PV1c+rrfejq3Fc8THaTr5+PKkeHOVnwoP7KDIP37WR/fxNMFNgJ X-Received: by 10.84.213.136 with SMTP id g8mr7349149pli.339.1509726786419; Fri, 03 Nov 2017 09:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509726786; cv=none; d=google.com; s=arc-20160816; b=CVhxNikHfCaCjNNvYimRMkUdPfmmTYk+SROZ24Yu36Jycp2Ahid+xxNWQEripl3H9h QR1Q4JD/8z85NWogLvQ5Psokc+MerBZrEONqNOyxGPIEvl602xDBL+zS1Moo1DlfwtkF qwaDGSqA0MBxOLNlxZXW0bCVCCAferVjsN5AnAlWw0tLW3535bOV/CYIjxlVSLrLgn0S 1/i5r8HpA5B+O08Fa+ea9OQKMiRqmp0qsI5C5BV3Ut2oqCzbVAGeOmjh0eWKvYuzDzz4 uZFYsVINIhqWBKjvIaQDvsON1UnAcnOHCUoChlA/tMD+STULu8trKbnrqPWJCx1pS3Ic AdKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=L67CBrF6jvmJLe3poLwgbo+OFfgz2BGiGdz5mVaq9R8=; b=nN8ksMVu5fAoWG7S5ZYwOU4V61xZD/5DXzzC1hZuajTWVMcfeZP11Q1T/zVw6XbhAD 9FTb8h3BOZtdgwLT5Hbd1sGh/TQEWW5AAu3HuqztwCWEEVcyOXaJdw6bnL08cH5ZjTz4 B6Yom5wk7u3zP+vtKXuIQNkaGmdz9MOVO6PyS07y4zcSsQYF4f515KE5HRobKgSlykDA 7irvOIjS7bGVOVb05lECi9+dWe9D8p9NzVWQrnl/9GDYX79UkVy0rusD1SeBuyb4jqBc S1UgyNDPShKCE1At/9UsygJKphjI+TNjJ1MkoJN2wsDDMpwj5IAjLuZAV/5VoU6Cz+4J pbKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si6308632pgq.678.2017.11.03.09.33.06; Fri, 03 Nov 2017 09:33:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756151AbdKCQdE (ORCPT + 26 others); Fri, 3 Nov 2017 12:33:04 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:62219 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755977AbdKCQdB (ORCPT ); Fri, 3 Nov 2017 12:33:01 -0400 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.129]) with ESMTPA (Nemesis) id 0MYHJs-1dfwlT1NL6-00Uoik; Fri, 03 Nov 2017 17:32:31 +0100 From: Arnd Bergmann To: Wolfgang Grandegger , Marc Kleine-Budde Cc: Arnd Bergmann , "David S. Miller" , Kees Cook , Allen Pais , Stephane Grosjean , Johan Hovold , =?utf-8?b?7LaU7KeA7Zi4?= , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] can: peak_usb: remove some 'struct timeval' users Date: Fri, 3 Nov 2017 17:31:36 +0100 Message-Id: <20171103163220.3799742-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:/LCdvyroFt+daSO3yYKLspZC5Afz7wmFkhhBrBRVkNYbEZexHpW Oz1qd646AWDF1OwyC0R8ssHarl6nBsfxqmy2eBZ6eG16N03TlBnWtfQxX8Lwn7Lt5P+cU/6 LPA4k+UpUd59Etg+vKHNvnTdpYNdnFRQL7OmZwDZlXwFfTcCuguvbq4pQt4I20BwbA/3afG 4xMYxsGEey+t0hgeungzQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:El1vHa/DNr8=:tul7aSLBdV6+ycBg9QdTHu jf3LA4d0R01mPtOxXbxjnZ2rrAbka6lWrk2AS2y5vokozyFDQQNrttcYUJZBUomCyKByHDMyq zEltAeSiSG7FpIs10bKqG46IYJl6uTe2PSpyHWQFF837k1Uu/+V9lsM9htkujCnRRAy41xyS9 UYccC6o8emodw8e/gEdT/HMlV1DqevMmlBFK6ThBlZSJ/r/Bid0Sy9xzgRG3UsN88XkSN5F3w FbDbSMTbvBLu18WF0qc1rl0Uldpb5wUlJ8FTJ/BQrDFuY0Ij0RKwFaFJoDXwY1X9bcpJisMtK sxZR7oox0eu5Y1BSUQ6E+h7azk7mQoCtEZYKzRvWre2Y19HNQf9lzzcReS46E3AcDIG3Txb/h O3d+a0yf0eLP4y9TazyKgSdnz2zIxgK6k/1+c3S0tic+rRNVAox7vimo9bMH+wUBIUVaiYSJ0 8l1qRaolMmZUI8CwbTs0k0lhuHmDfOVyhsNACE9etjx9hmUWEcjqzFqy1mTo4AkRb0JlMuihV XWRVvcVhoQGIbIlFtg1+IZdOXsgDRY0vbnoYVZcNb2y0xHor20zF3YOu7pH6Mf4rM1fITN5lf woiR3zTXGlNRhoHlD9yL5Qm+KL0NLfuPNhblmkx584gIkEjZblk75Xo88DDbh3MrbtjdIh+VB 9RMIElkpO5mfSUmSHf5hWS2BUIhD/wQnJ/KIG3xZLQLOES9OdChPAruNH3iirjuTZ2DnCb16S u88Zvu6HiBowcFXzGkt4TZx5OnlxKLjiM/dqWQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/can/usb/peak_usb/pcan_usb.c | 9 +++------ drivers/net/can/usb/peak_usb/pcan_usb_core.c | 15 +++++++-------- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 3 +-- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 9 +++------ 4 files changed, 14 insertions(+), 22 deletions(-) -- 2.9.0 diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c index 25a9b79cc42d..f530a80f5051 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -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 */ @@ -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++; @@ -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); @@ -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++; diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c index 1ca76e03e965..695a75a9b4bb 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c @@ -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; @@ -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(); } } @@ -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); } diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h index c01316cac354..b9a221ea7e5c 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h @@ -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); diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c index bbdd6058cd2f..0105fbfea273 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c @@ -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); @@ -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; @@ -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 */ @@ -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); From patchwork Fri Nov 3 16:31:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 117951 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3667754qgn; Fri, 3 Nov 2017 09:33:14 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QTvFM518mGC9HGa9h48eIIdCNIr/sCVhPT+cKkaoEDJGwoAQ+lbPmWa5nt5UQ5APw4zISw X-Received: by 10.98.24.20 with SMTP id 20mr8209218pfy.71.1509726793895; Fri, 03 Nov 2017 09:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509726793; cv=none; d=google.com; s=arc-20160816; b=KO5AVbRScTcbRg5mlu0/+uWR4DhkRhS6Lo4Kfx2F1P9nEVCUc1ogmsMgm7wtVX0mYj sbzkfiFZjM4RMCnY/b4liiAlEJYbdxghciY1aoIqBAOVhxzIKjJp963UYMSGcBbTGdcK oZdJbE0Q6XKuW/NIeTsU7t2wUAccWE4uavvX3Rpl6Ivqs8j9ZyQYPPG8WecCV2PaK+xm /F15CnQMGMQokoSXP7utKdPXUtB3pAaTvcErxeZTg1eG7d6nXOs3X4FE7TjieDyvTupt Y9q0t4K8/qqdy07jhjQm0HaAtjuhK4QcfgFKw4cRfmI2UdQ7iDiBnKt222aujUSSkAtt xF0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=s6rLMe57GYm+89MDYlnm5m/MeDJYPGAUdKlxXlIiqYo=; b=cGflSiZ6zJV3tl9LcYLndbt65y6ZmNR6QmBMfo1Eq2vM6bEpS+obyCJSDdKV7blEaU 8lQ6pAv5/x08Q14WlaqdhuX6S7LlIkQrxDi13yvNnMGXrOXeEtzucH3O/QWAAoWHl1n+ uHKAh2Md1FuFCRDJvEm6rGctjfw0cUpA+VJaG9MNYuXdR5t9yDmvWvcawYTJjXb78uYK INGKSm0ss4dcKFKxRo+CSZTax4iqARAUDwdP7O6W6eYGiALX8rEP2m6AHOwbgGXc978a /AMmWAQ2ytdT3pSYuALPrMXF5VgThp1J0EGOLsI5HHj99aBfhoTpvqX298tHWYzenPCW rwcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si6308632pgq.678.2017.11.03.09.33.13; Fri, 03 Nov 2017 09:33:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756189AbdKCQdM (ORCPT + 26 others); Fri, 3 Nov 2017 12:33:12 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:57777 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755977AbdKCQdG (ORCPT ); Fri, 3 Nov 2017 12:33:06 -0400 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lhp7m-1dOgol3gXa-00nAaK; Fri, 03 Nov 2017 17:32:50 +0100 From: Arnd Bergmann To: Wolfgang Grandegger , Marc Kleine-Budde Cc: Arnd Bergmann , Stephane Grosjean , =?utf-8?b?7LaU7KeA7Zi4?= , Johan Hovold , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] can: peak_usb: use ktime_t consistently Date: Fri, 3 Nov 2017 17:31:37 +0100 Message-Id: <20171103163220.3799742-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171103163220.3799742-1-arnd@arndb.de> References: <20171103163220.3799742-1-arnd@arndb.de> X-Provags-ID: V03:K0:/E1BfImCKFLcUZhcGCTTQ+2gbE1iQw4z+wqT/GhynmtFu2FAnsU IUlsTFpe21h7KCEKf/0fXQosqDYSefatWI6j9SlM9DU+0mrptaiCQkz6/vtfvMTc3GdlGAx nuEcpLL5BwTVAtVfwq6AMrIX5eb1vyd71SVQhSs7RmddQf9vIPNDZj70FAeIn8IBKRyIrhk Mh9lz+ndvNG5Y/u09VZ/w== X-UI-Out-Filterresults: notjunk:1; V01:K0:pmvxq/TWXMQ=:VyXTvX1/PcNJvW77TGQ3Zb EDbfsQUgLy86wbS0LJiDo6gvjIaU6FrHI6a+t7v4oTyHBwhD5CLgSfdiPHHAi2Gt+qWF5cHpa U6CNeSdGcdUtbqWZAR4YYn62Bqbqyf4p6DiRT9zReXgm1k3ehe9pIGbyjSOfOd4BU/dkMpUQa 7+LwWn052XU0oCsaJScxohJXGVT6c59C36uVGC0oHUGUTcPSbs2QYU78KYnZtx0xqQFhe+Ks1 XWzjm6C0aKVPNj+ItWMNBLp5lG5PB46+xT5G+m2D3NnXhpzCTS6gjwQ+bNvvKSgK3Cbxa9ZK0 C/BvhdcdVbPNXht2NGY+DiWyBtCj4RPXJRlpkB2lTlxQ69P9gQr2C3dWupvb/Pw0ijC4otuCM uNxJg/eU4YcnHqimDgi/aeEwSkZD6xfUxNye+LAHg4MR9kxqDgBzyLJjliOwS000EKsCFnosy oSJsoOtOEbeL9JemrWUPSGg/e2NPj1KtJSR7t6L7ONaHo0VYHDwfDnOmWMMGjwMLmtsN7pZZo 22mMpJaY8sd62L3kDk4X7aGj1/jcmoqugjLj9G0tTFt/u4lExsJ7+yjb56hnYhYt9nB8CTPar aNLQstEuH1DrETLfuzvE2YOaqWCmyR2p7Kfxvmi2eHGxEUkYoBw5colhcfVef//5Hq2bUIFOg FwbtbIeiWyg4+U+r5N7nCUYaJON9ZNoeios4r7025bHNAtzDgI+TrCUwgBP92eVn7s7zGbWSX 46Z2bCP9MMG6jE8bh0fYL8TZlVjia/yagWVllg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This changes the calculation of the timestamps to use ktime_t instead of struct timeval as the base. This gets rid of one of the few remaining users of the deprecated ktime_to_timeval() and timeval_to_ktime() helpers. The code should also get more efficient, as we have now removed all of the divisions. I have left the cut-off for resetting the counters as 4.200 seconds, in order to leave the behavior unchanged otherwise. Signed-off-by: Arnd Bergmann --- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 46 +++++++++------------------- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 +- 2 files changed, 15 insertions(+), 33 deletions(-) -- 2.9.0 diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c index 695a75a9b4bb..8f699ee6a528 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c @@ -80,21 +80,6 @@ void peak_usb_init_time_ref(struct peak_time_ref *time_ref, } } -static void peak_usb_add_us(struct timeval *tv, u32 delta_us) -{ - /* number of s. to add to final time */ - u32 delta_s = delta_us / 1000000; - - delta_us -= delta_s * 1000000; - - tv->tv_usec += delta_us; - if (tv->tv_usec >= 1000000) { - tv->tv_usec -= 1000000; - delta_s++; - } - tv->tv_sec += delta_s; -} - /* * sometimes, another now may be more recent than current one... */ @@ -103,7 +88,7 @@ void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now) time_ref->ts_dev_2 = ts_now; /* should wait at least two passes before computing */ - if (time_ref->tv_host.tv_sec > 0) { + if (ktime_to_ns(time_ref->tv_host) > 0) { u32 delta_ts = time_ref->ts_dev_2 - time_ref->ts_dev_1; if (time_ref->ts_dev_2 < time_ref->ts_dev_1) @@ -118,26 +103,26 @@ 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) { - if (time_ref->tv_host_0.tv_sec == 0) { + if (ktime_to_ns(time_ref->tv_host_0) == 0) { /* use monotonic clock to correctly compute further deltas */ - time_ref->tv_host_0 = ktime_to_timeval(ktime_get()); - time_ref->tv_host.tv_sec = 0; + time_ref->tv_host_0 = ktime_get(); + time_ref->tv_host = ktime_set(0, 0); } else { /* - * delta_us should not be >= 2^32 => delta_s should be < 4294 + * delta_us should not be >= 2^32 => delta should be < 4294s * handle 32-bits wrapping here: if count of s. reaches 4200, * reset counters and change time base */ - if (time_ref->tv_host.tv_sec != 0) { - u32 delta_s = time_ref->tv_host.tv_sec - - time_ref->tv_host_0.tv_sec; - if (delta_s > 4200) { + if (ktime_to_ns(time_ref->tv_host)) { + ktime_t delta = ktime_sub(time_ref->tv_host, + time_ref->tv_host_0); + if (ktime_to_ns(delta) > (4200ull * NSEC_PER_SEC)) { time_ref->tv_host_0 = time_ref->tv_host; time_ref->ts_total = 0; } } - time_ref->tv_host = ktime_to_timeval(ktime_get()); + time_ref->tv_host = ktime_get(); time_ref->tick_count++; } @@ -146,13 +131,12 @@ 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 + * compute time according to current ts and time_ref data */ 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; + /* protect from getting time before setting now */ + if (ktime_to_ns(time_ref->tv_host)) { u64 delta_us; delta_us = ts - time_ref->ts_dev_2; @@ -164,9 +148,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time) 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); - *time = timeval_to_ktime(tv); + *time = ktime_add_us(time_ref->tv_host_0, delta_us); } else { *time = ktime_get(); } diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h index b9a221ea7e5c..29f03dccca10 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h @@ -96,7 +96,7 @@ extern const struct peak_usb_adapter pcan_usb_pro_fd; extern const struct peak_usb_adapter pcan_usb_x6; struct peak_time_ref { - struct timeval tv_host_0, tv_host; + ktime_t tv_host_0, tv_host; u32 ts_dev_1, ts_dev_2; u64 ts_total; u32 tick_count;