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

atm: mpoa: remove 32-bit timekeeping

net/atm/mpoa_* files use 'struct timeval' to store event
timestamps. struct timeval uses a 32-bit seconds field which will
overflow in the year 2038 and beyond. Morever, the timestamps are being
compared only to get seconds elapsed, so struct timeval which stores
a seconds and microseconds field is an overkill. This patch replaces
the use of struct timeval with time64_t to store a 64-bit seconds field.

Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Tina Ruchandani and committed by
David S. Miller
d750dbdc 59c03699

+43 -40
+1 -1
net/atm/common.c
··· 14 14 #include <linux/capability.h> 15 15 #include <linux/mm.h> 16 16 #include <linux/sched/signal.h> 17 - #include <linux/time.h> /* struct timeval */ 17 + #include <linux/time64.h> /* 64-bit time for seconds */ 18 18 #include <linux/skbuff.h> 19 19 #include <linux/bitops.h> 20 20 #include <linux/init.h>
+5 -4
net/atm/mpc.c
··· 1089 1089 msg->type = SND_MPOA_RES_RQST; 1090 1090 msg->content.in_info = entry->ctrl_info; 1091 1091 msg_to_mpoad(msg, mpc); 1092 - do_gettimeofday(&(entry->reply_wait)); 1092 + entry->reply_wait = ktime_get_seconds(); 1093 1093 mpc->in_ops->put(entry); 1094 1094 return; 1095 1095 } ··· 1099 1099 msg->type = SND_MPOA_RES_RQST; 1100 1100 msg->content.in_info = entry->ctrl_info; 1101 1101 msg_to_mpoad(msg, mpc); 1102 - do_gettimeofday(&(entry->reply_wait)); 1102 + entry->reply_wait = ktime_get_seconds(); 1103 1103 mpc->in_ops->put(entry); 1104 1104 return; 1105 1105 } ··· 1175 1175 } 1176 1176 1177 1177 entry->ctrl_info = msg->content.in_info; 1178 - do_gettimeofday(&(entry->tv)); 1179 - do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */ 1178 + entry->time = ktime_get_seconds(); 1179 + /* Used in refreshing func from now on */ 1180 + entry->reply_wait = ktime_get_seconds(); 1180 1181 entry->refresh_time = 0; 1181 1182 ddprintk_cont("entry->shortcut = %p\n", entry->shortcut); 1182 1183
+23 -25
net/atm/mpoa_caches.c
··· 117 117 118 118 memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN); 119 119 entry->ctrl_info.in_dst_ip = dst_ip; 120 - do_gettimeofday(&(entry->tv)); 120 + entry->time = ktime_get_seconds(); 121 121 entry->retry_time = client->parameters.mpc_p4; 122 122 entry->count = 1; 123 123 entry->entry_state = INGRESS_INVALID; ··· 148 148 if (qos != NULL) 149 149 msg.qos = qos->qos; 150 150 msg_to_mpoad(&msg, mpc); 151 - do_gettimeofday(&(entry->reply_wait)); 151 + entry->reply_wait = ktime_get_seconds(); 152 152 entry->entry_state = INGRESS_RESOLVING; 153 153 } 154 154 if (entry->shortcut != NULL) ··· 171 171 if (qos != NULL) 172 172 msg.qos = qos->qos; 173 173 msg_to_mpoad(&msg, mpc); 174 - do_gettimeofday(&(entry->reply_wait)); 174 + entry->reply_wait = ktime_get_seconds(); 175 175 } 176 176 177 177 return CLOSED; ··· 227 227 static void clear_count_and_expired(struct mpoa_client *client) 228 228 { 229 229 in_cache_entry *entry, *next_entry; 230 - struct timeval now; 230 + time64_t now; 231 231 232 - do_gettimeofday(&now); 232 + now = ktime_get_seconds(); 233 233 234 234 write_lock_bh(&client->ingress_lock); 235 235 entry = client->in_cache; 236 236 while (entry != NULL) { 237 237 entry->count = 0; 238 238 next_entry = entry->next; 239 - if ((now.tv_sec - entry->tv.tv_sec) 240 - > entry->ctrl_info.holding_time) { 239 + if ((now - entry->time) > entry->ctrl_info.holding_time) { 241 240 dprintk("holding time expired, ip = %pI4\n", 242 241 &entry->ctrl_info.in_dst_ip); 243 242 client->in_ops->remove_entry(entry, client); ··· 252 253 253 254 struct atm_mpoa_qos *qos; 254 255 in_cache_entry *entry; 255 - struct timeval now; 256 + time64_t now; 256 257 struct k_message msg; 257 258 258 - do_gettimeofday(&now); 259 + now = ktime_get_seconds(); 259 260 260 261 read_lock_bh(&client->ingress_lock); 261 262 entry = client->in_cache; 262 263 while (entry != NULL) { 263 264 if (entry->entry_state == INGRESS_RESOLVING) { 264 - if ((now.tv_sec - entry->hold_down.tv_sec) < 265 - client->parameters.mpc_p6) { 265 + 266 + if ((now - entry->hold_down) 267 + < client->parameters.mpc_p6) { 266 268 entry = entry->next; /* Entry in hold down */ 267 269 continue; 268 270 } 269 - if ((now.tv_sec - entry->reply_wait.tv_sec) > 270 - entry->retry_time) { 271 + if ((now - entry->reply_wait) > entry->retry_time) { 271 272 entry->retry_time = MPC_C1 * (entry->retry_time); 272 273 /* 273 274 * Retry time maximum exceeded, 274 275 * put entry in hold down. 275 276 */ 276 277 if (entry->retry_time > client->parameters.mpc_p5) { 277 - do_gettimeofday(&(entry->hold_down)); 278 + entry->hold_down = ktime_get_seconds(); 278 279 entry->retry_time = client->parameters.mpc_p4; 279 280 entry = entry->next; 280 281 continue; 281 282 } 282 283 /* Ask daemon to send a resolution request. */ 283 - memset(&(entry->hold_down), 0, sizeof(struct timeval)); 284 + memset(&entry->hold_down, 0, sizeof(time64_t)); 284 285 msg.type = SND_MPOA_RES_RTRY; 285 286 memcpy(msg.MPS_ctrl, client->mps_ctrl_addr, ATM_ESA_LEN); 286 287 msg.content.in_info = entry->ctrl_info; ··· 288 289 if (qos != NULL) 289 290 msg.qos = qos->qos; 290 291 msg_to_mpoad(&msg, client); 291 - do_gettimeofday(&(entry->reply_wait)); 292 + entry->reply_wait = ktime_get_seconds(); 292 293 } 293 294 } 294 295 entry = entry->next; ··· 299 300 /* Call this every MPC-p5 seconds. */ 300 301 static void refresh_entries(struct mpoa_client *client) 301 302 { 302 - struct timeval now; 303 + time64_t now; 303 304 struct in_cache_entry *entry = client->in_cache; 304 305 305 306 ddprintk("refresh_entries\n"); 306 - do_gettimeofday(&now); 307 + now = ktime_get_seconds(); 307 308 308 309 read_lock_bh(&client->ingress_lock); 309 310 while (entry != NULL) { 310 311 if (entry->entry_state == INGRESS_RESOLVED) { 311 312 if (!(entry->refresh_time)) 312 313 entry->refresh_time = (2 * (entry->ctrl_info.holding_time))/3; 313 - if ((now.tv_sec - entry->reply_wait.tv_sec) > 314 + if ((now - entry->reply_wait) > 314 315 entry->refresh_time) { 315 316 dprintk("refreshing an entry.\n"); 316 317 entry->entry_state = INGRESS_REFRESHING; ··· 479 480 480 481 memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN); 481 482 entry->ctrl_info = msg->content.eg_info; 482 - do_gettimeofday(&(entry->tv)); 483 + entry->time = ktime_get_seconds(); 483 484 entry->entry_state = EGRESS_RESOLVED; 484 485 dprintk("new_eg_cache_entry cache_id %u\n", 485 486 ntohl(entry->ctrl_info.cache_id)); ··· 494 495 495 496 static void update_eg_cache_entry(eg_cache_entry *entry, uint16_t holding_time) 496 497 { 497 - do_gettimeofday(&(entry->tv)); 498 + entry->time = ktime_get_seconds(); 498 499 entry->entry_state = EGRESS_RESOLVED; 499 500 entry->ctrl_info.holding_time = holding_time; 500 501 } ··· 502 503 static void clear_expired(struct mpoa_client *client) 503 504 { 504 505 eg_cache_entry *entry, *next_entry; 505 - struct timeval now; 506 + time64_t now; 506 507 struct k_message msg; 507 508 508 - do_gettimeofday(&now); 509 + now = ktime_get_seconds(); 509 510 510 511 write_lock_irq(&client->egress_lock); 511 512 entry = client->eg_cache; 512 513 while (entry != NULL) { 513 514 next_entry = entry->next; 514 - if ((now.tv_sec - entry->tv.tv_sec) 515 - > entry->ctrl_info.holding_time) { 515 + if ((now - entry->time) > entry->ctrl_info.holding_time) { 516 516 msg.type = SND_EGRESS_PURGE; 517 517 msg.content.eg_info = entry->ctrl_info; 518 518 dprintk("egress_cache: holding time expired, cache_id = %u.\n",
+5 -4
net/atm/mpoa_caches.h
··· 2 2 #ifndef MPOA_CACHES_H 3 3 #define MPOA_CACHES_H 4 4 5 + #include <linux/time64.h> 5 6 #include <linux/netdevice.h> 6 7 #include <linux/types.h> 7 8 #include <linux/atm.h> ··· 17 16 typedef struct in_cache_entry { 18 17 struct in_cache_entry *next; 19 18 struct in_cache_entry *prev; 20 - struct timeval tv; 21 - struct timeval reply_wait; 22 - struct timeval hold_down; 19 + time64_t time; 20 + time64_t reply_wait; 21 + time64_t hold_down; 23 22 uint32_t packets_fwded; 24 23 uint16_t entry_state; 25 24 uint32_t retry_time; ··· 54 53 typedef struct eg_cache_entry{ 55 54 struct eg_cache_entry *next; 56 55 struct eg_cache_entry *prev; 57 - struct timeval tv; 56 + time64_t time; 58 57 uint8_t MPS_ctrl_ATM_addr[ATM_ESA_LEN]; 59 58 struct atm_vcc *shortcut; 60 59 uint32_t packets_rcvd;
+9 -6
net/atm/mpoa_proc.c
··· 8 8 #include <linux/mm.h> 9 9 #include <linux/module.h> 10 10 #include <linux/proc_fs.h> 11 - #include <linux/time.h> 11 + #include <linux/ktime.h> 12 12 #include <linux/seq_file.h> 13 13 #include <linux/uaccess.h> 14 14 #include <linux/atmmpc.h> ··· 138 138 int i; 139 139 in_cache_entry *in_entry; 140 140 eg_cache_entry *eg_entry; 141 - struct timeval now; 141 + time64_t now; 142 142 unsigned char ip_string[16]; 143 143 144 144 if (v == SEQ_START_TOKEN) { ··· 148 148 149 149 seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num); 150 150 seq_printf(m, "Ingress Entries:\nIP address State Holding time Packets fwded VPI VCI\n"); 151 - do_gettimeofday(&now); 151 + now = ktime_get_seconds(); 152 152 153 153 for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) { 154 + unsigned long seconds_delta = now - in_entry->time; 155 + 154 156 sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip); 155 157 seq_printf(m, "%-16s%s%-14lu%-12u", 156 158 ip_string, 157 159 ingress_state_string(in_entry->entry_state), 158 160 in_entry->ctrl_info.holding_time - 159 - (now.tv_sec-in_entry->tv.tv_sec), 161 + seconds_delta, 160 162 in_entry->packets_fwded); 161 163 if (in_entry->shortcut) 162 164 seq_printf(m, " %-3d %-3d", ··· 171 169 seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n"); 172 170 for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) { 173 171 unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr; 172 + unsigned long seconds_delta = now - eg_entry->time; 173 + 174 174 for (i = 0; i < ATM_ESA_LEN; i++) 175 175 seq_printf(m, "%02x", p[i]); 176 176 seq_printf(m, "\n%-16lu%s%-14lu%-15u", 177 177 (unsigned long)ntohl(eg_entry->ctrl_info.cache_id), 178 178 egress_state_string(eg_entry->entry_state), 179 - (eg_entry->ctrl_info.holding_time - 180 - (now.tv_sec-eg_entry->tv.tv_sec)), 179 + (eg_entry->ctrl_info.holding_time - seconds_delta), 181 180 eg_entry->packets_rcvd); 182 181 183 182 /* latest IP address */