summarylogtreecommitdiffstats
path: root/kernel_do_gettimeofday_fix.patch
blob: bbfa646bd802c8e044e180e6c3e8be7420555284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
commit 06cf40760506f7aeda1daee7fe8e5e330915daaa
Author: Bruno Santos <brunomanuelsantos@tecnico.ulisboa.pt>
Date:   Tue Jun 18 18:37:17 2019 +0200

    Fix use of deprecated do_gettimeofday()
    
    do_gettimeofday() is deprecated because of the year 2038 overflow. Since
    this driver uses it extensively and it's no longer available in recent
    kernels, we need to convert it to something else.
    
    The code could be improved, this is a least effort, half scripted fix.

diff --git a/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.c b/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.c
index d6d4228..7f019fb 100644
--- a/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.c	
+++ b/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.c	
@@ -235,24 +235,14 @@ void ixxat_dump_mem(char *prompt, void *p, int l)
         DUMP_WIDTH, 1, p, l, false);
 }
 
-static void ixxat_pci_add_us(struct timeval *tv, u64 delta_us)
+static void ixxat_pci_add_us(ktime_t *tv, u64 delta_us)
 {
-        /* number of s. to add to final time */
-        u32 delta_s = div_u64(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;
+        tv += delta_us * 100;
 }
 
 void ixxat_pci_get_ts_tv(struct ixx_pci_priv *dev, u32 ts, ktime_t *k_time)
 {
-        struct timeval tv = dev->time_ref.tv_host_0;
+        ktime_t tv = dev->time_ref.tv_host_0;
 
         if (ts < dev->time_ref.ts_dev_last) {
                 ixxat_pci_update_ts_now(dev, ts);
@@ -261,7 +251,7 @@ void ixxat_pci_get_ts_tv(struct ixx_pci_priv *dev, u32 ts, ktime_t *k_time)
         dev->time_ref.ts_dev_last = ts;
         ixxat_pci_add_us(&tv, ts - dev->time_ref.ts_dev_0);
 
-        *k_time = timeval_to_ktime(tv);
+        *k_time = tv;
 }
 
 void ixxat_pci_update_ts_now(struct ixx_pci_priv *dev, u32 hw_time_base)
@@ -278,7 +268,7 @@ void ixxat_pci_update_ts_now(struct ixx_pci_priv *dev, u32 hw_time_base)
 void ixxat_pci_set_ts_now(struct ixx_pci_priv *dev, u32 hw_time_base)
 {
         dev->time_ref.ts_dev_0 = hw_time_base;
-        do_gettimeofday(&dev->time_ref.tv_host_0);
+        dev->time_ref.tv_host_0 = ktime_get_real();
         dev->time_ref.ts_dev_last = hw_time_base;
 }
 
@@ -543,9 +533,9 @@ static int ixxat_pci_set_datatiming(struct net_device *netdev)
 
 static const struct net_device_ops ixxat_pci_netdev_ops = { .ndo_open =
                 ixxat_pci_ndo_open, .ndo_stop = ixxat_pci_ndo_stop,
-                .ndo_start_xmit = ixxat_pci_ndo_start_xmit, 
+                .ndo_start_xmit = ixxat_pci_ndo_start_xmit,
 #ifdef CANFD_CAPABLE
-.ndo_change_mtu = can_change_mtu, 
+.ndo_change_mtu = can_change_mtu,
 #endif
 };
 
@@ -664,7 +654,7 @@ static void ixxat_pci_disconnect(struct pci_dev *dev)
                 char name[IFNAMSIZ];
                 printk("ixxat_pci_disconnect\n");
                 strncpy(name, netdev->name, IFNAMSIZ);
-                
+
                 priv_prev_siblings = priv->prev_siblings;
 
                 priv->next_siblings = NULL;
@@ -672,12 +662,12 @@ static void ixxat_pci_disconnect(struct pci_dev *dev)
                         priv->adapter->dev_free(priv);
 
                 unregister_netdev(netdev);
-                
+
                 if (!priv_prev_siblings) {
                         pci_set_drvdata(dev, NULL);
                         pci_disable_device(dev);
                 }
-                
+
                 free_candev(netdev);
         }
 }
diff --git a/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.h b/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.h
index 8e94b34..0f0f3e2 100644
--- a/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.h	
+++ b/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_core.h	
@@ -241,7 +241,7 @@ struct ixx_canfd_msg {
 } __packed;
 
 struct ixx_time_ref {
-        struct timeval tv_host_0;
+        ktime_t tv_host_0;
         u32 ts_dev_0;
         u32 ts_dev_last;
 };
diff --git a/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_ib_active.c b/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_ib_active.c
index 6cc4985..cd0c50a 100644
--- a/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_ib_active.c	
+++ b/SocketCAN - Linux (V1.1.148.0)/can-ibxxx_socketcan/ixx_pci_ib_active.c	
@@ -369,7 +369,7 @@ static int ixx_act_ib_xxx_rcv_cmd(struct ixx_pci_interface *intf, u32 *rx_fifo,
         u32* res_size;
         struct ixx_dal_req *res_dal_req;
         u32 read_index, write_index, data_offset;
-        struct timeval start, end;
+        ktime_t start, end;
         size_t dal_size = sizeof(struct ixx_dal_req);
 
         write_index = rx_fifo[CAN_IB2X0_PCR_RES_WRITE_IDX];
@@ -378,10 +378,10 @@ static int ixx_act_ib_xxx_rcv_cmd(struct ixx_pci_interface *intf, u32 *rx_fifo,
         if (rx_fifo[CAN_IB2X0_PCR_RES_DIR] != CAN_IB2X0_PCR_RESDIR_DTOH)
                 return -EBADSLT;
 
-        do_gettimeofday(&start);
+        start = ktime_get_real();
         end = start;
 
-        while ((end.tv_usec - start.tv_usec) < CAN_IB2X0_CMD_TIMEOUT_US) {
+        while ((end - start) < (CAN_IB2X0_CMD_TIMEOUT_US * 100)) {
                 if (++read_index == rx_fifo[CAN_IB2X0_PCR_RES_NUM_OBJ])
                         read_index = 0;
 
@@ -437,8 +437,9 @@ static int ixx_act_ib_xxx_rcv_cmd(struct ixx_pci_interface *intf, u32 *rx_fifo,
 
                 return dal_res->ret_code;
 
-                cmd_continue: do_gettimeofday(&end);
-        }
+		cmd_continue:
+			end = ktime_get_real();
+	}
 
         return err;
 }
diff --git a/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.c b/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.c
index 5d542a3..696e5d4 100644
--- a/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.c	
+++ b/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.c	
@@ -94,24 +94,14 @@ void ixxat_dump_mem(char *prompt, void *p, int l)
         DUMP_WIDTH, 1, p, l, false);
 }
 
-static void ixxat_usb_add_us(struct timeval *tv, u64 delta_us)
+static void ixxat_usb_add_us(ktime_t *tv, u64 delta_us)
 {
-        /* number of s. to add to final time */
-        u32 delta_s = div_u64(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;
+        *tv += delta_us * 100;
 }
 
 void ixxat_usb_get_ts_tv(struct ixx_usb_device *dev, u32 ts, ktime_t *k_time)
 {
-        struct timeval tv = dev->time_ref.tv_host_0;
+        ktime_t tv = dev->time_ref.tv_host_0;
 
         if (ts < dev->time_ref.ts_dev_last) {
                 ixxat_usb_update_ts_now(dev, ts);
@@ -121,7 +111,7 @@ void ixxat_usb_get_ts_tv(struct ixx_usb_device *dev, u32 ts, ktime_t *k_time)
         ixxat_usb_add_us(&tv, ts - dev->time_ref.ts_dev_0);
 
         if(k_time)
-                *k_time = timeval_to_ktime(tv);
+                *k_time = tv;
 }
 
 void ixxat_usb_update_ts_now(struct ixx_usb_device *dev, u32 hw_time_base)
@@ -138,7 +128,7 @@ void ixxat_usb_update_ts_now(struct ixx_usb_device *dev, u32 hw_time_base)
 void ixxat_usb_set_ts_now(struct ixx_usb_device *dev, u32 hw_time_base)
 {
         dev->time_ref.ts_dev_0 = hw_time_base;
-        do_gettimeofday(&dev->time_ref.tv_host_0);
+        dev->time_ref.tv_host_0 = ktime_get_real();
         dev->time_ref.ts_dev_last = hw_time_base;
 }
 
@@ -178,7 +168,7 @@ static void ixxat_usb_read_bulk_callback(struct urb *urb)
         /* protect from any incoming empty msgs */
         if ((urb->actual_length > 0) && (dev->adapter->dev_decode_buf)) {
                 /* handle these kinds of msgs only if _start callback called */
-                if (dev->state & IXXAT_USB_STATE_STARTED) 
+                if (dev->state & IXXAT_USB_STATE_STARTED)
                         err = dev->adapter->dev_decode_buf(dev, urb);
         }
 
@@ -633,7 +623,7 @@ static int ixxat_usb_get_berr_counter(const struct net_device *netdev,
 {
         struct ixx_usb_device* dev = (struct ixx_usb_device*) netdev_priv(
                         netdev);
-  
+
         *bec = dev->bec;
 
         return 0;
@@ -641,9 +631,9 @@ static int ixxat_usb_get_berr_counter(const struct net_device *netdev,
 
 static const struct net_device_ops ixx_usb_netdev_ops = { .ndo_open =
                 ixxat_usb_ndo_open, .ndo_stop = ixxat_usb_ndo_stop,
-                .ndo_start_xmit = ixxat_usb_ndo_start_xmit, 
+                .ndo_start_xmit = ixxat_usb_ndo_start_xmit,
 #ifdef CANFD_CAPABLE
-                .ndo_change_mtu = can_change_mtu, 
+                .ndo_change_mtu = can_change_mtu,
 #endif
                                                         };
 
@@ -689,7 +679,7 @@ static int ixxat_usb_create_dev(struct ixx_usb_adapter *ixx_usb_adapter,
         dev->adapter = ixx_usb_adapter;
         dev->ctrl_idx = ctrl_idx;
         dev->state = IXXAT_USB_STATE_CONNECTED;
-        
+
         ep_off = ixx_usb_adapter->has_bgi_ep ? 1 : 0;
 
         /* Add +1 because of the bgi endpoint */
@@ -701,7 +691,7 @@ static int ixxat_usb_create_dev(struct ixx_usb_adapter *ixx_usb_adapter,
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 3)
         dev->can.data_bittiming_const = &ixx_usb_adapter->data_bittiming_const;
 #endif
-  
+
         dev->can.do_set_bittiming = ixxat_usb_set_bittiming;
         dev->can.do_set_mode = ixxat_usb_set_mode;
         dev->can.do_get_berr_counter = ixxat_usb_get_berr_counter;
@@ -782,7 +772,7 @@ static void ixxat_usb_disconnect(struct usb_interface *intf)
                 dev->next_siblings = NULL;
                 if (dev->adapter->dev_free)
                         dev->adapter->dev_free(dev);
-                    
+
                 free_candev(netdev);
                 dev_dbg(&intf->dev, "%s removed\n", name);
         }
@@ -824,12 +814,12 @@ static int ixxat_usb_probe(struct usb_interface *intf,
                 if (err)
                         return err;
         }
-  
+
         if (ixx_usb_adapter->dev_power) {
                 err = ixx_usb_adapter->dev_power(usb_dev, IXXAT_USB_POWER_WAKEUP);
                 if (err)
                         return err;
-          
+
                 /* Give usb device some time to start its can controllers */
                 msleep(500);
         }
@@ -880,7 +870,7 @@ static int __init ixx_usb_init(void)
 
 static int ixxat_usb_do_device_exit(struct device *d, void *arg)
 {
-        struct usb_interface 
+        struct usb_interface
                 *intf = (struct usb_interface*)to_usb_interface(d);
         struct ixx_usb_device *dev;
 
diff --git a/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.h b/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.h
index 60dc02d..577f276 100644
--- a/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.h	
+++ b/SocketCAN - Linux (V1.1.148.0)/usb-to-can_socketcan/ixx_usb_core.h	
@@ -193,7 +193,7 @@ struct ixx_usb_adapter {
 };
 
 struct ixx_time_ref {
-        struct timeval tv_host_0;
+        ktime_t tv_host_0;
         u32 ts_dev_0;
         u32 ts_dev_last;
 };