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

[media] dvb-frontend: Replace timeval with ktime_t

struct timeval uses a 32-bit seconds representation which will
overflow in the year 2038 and beyond. This patch replaces
the usage of struct timeval with ktime_t which is a 64-bit
timestamp and is year 2038 safe.
This patch is part of a larger attempt to remove all instances
of 32-bit timekeeping variables (timeval, timespec, time_t)
which are not year 2038 safe, from the kernel.

[mchehab@osg.samsung.com: add a missing parenthesis, breaking compilation]
Suggested-by: Arnd Bergmann <arndb@arndb.de>
Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Tina Ruchandani and committed by
Mauro Carvalho Chehab
9056a23b d3525b63

+19 -37
+11 -30
drivers/media/dvb-core/dvb_frontend.c
··· 40 40 #include <linux/freezer.h> 41 41 #include <linux/jiffies.h> 42 42 #include <linux/kthread.h> 43 + #include <linux/ktime.h> 43 44 #include <asm/processor.h> 44 45 45 46 #include "dvb_frontend.h" ··· 891 890 fepriv->thread); 892 891 } 893 892 894 - s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime) 895 - { 896 - return ((curtime.tv_usec < lasttime.tv_usec) ? 897 - 1000000 - lasttime.tv_usec + curtime.tv_usec : 898 - curtime.tv_usec - lasttime.tv_usec); 899 - } 900 - EXPORT_SYMBOL(timeval_usec_diff); 901 - 902 - static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec) 903 - { 904 - curtime->tv_usec += add_usec; 905 - if (curtime->tv_usec >= 1000000) { 906 - curtime->tv_usec -= 1000000; 907 - curtime->tv_sec++; 908 - } 909 - } 910 - 911 893 /* 912 894 * Sleep until gettimeofday() > waketime + add_usec 913 895 * This needs to be as precise as possible, but as the delay is 914 896 * usually between 2ms and 32ms, it is done using a scheduled msleep 915 897 * followed by usleep (normally a busy-wait loop) for the remainder 916 898 */ 917 - void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec) 899 + void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec) 918 900 { 919 - struct timeval lasttime; 920 901 s32 delta, newdelta; 921 902 922 - timeval_usec_add(waketime, add_usec); 923 - 924 - do_gettimeofday(&lasttime); 925 - delta = timeval_usec_diff(lasttime, *waketime); 903 + ktime_add_us(*waketime, add_usec); 904 + delta = ktime_us_delta(ktime_get_real(), *waketime); 926 905 if (delta > 2500) { 927 906 msleep((delta - 1500) / 1000); 928 - do_gettimeofday(&lasttime); 929 - newdelta = timeval_usec_diff(lasttime, *waketime); 907 + newdelta = ktime_us_delta(ktime_get_real(), *waketime); 930 908 delta = (newdelta > delta) ? 0 : newdelta; 931 909 } 932 910 if (delta > 0) ··· 2443 2463 * include the initialization or start bit 2444 2464 */ 2445 2465 unsigned long swcmd = ((unsigned long) parg) << 1; 2446 - struct timeval nexttime; 2447 - struct timeval tv[10]; 2466 + ktime_t nexttime; 2467 + ktime_t tv[10]; 2448 2468 int i; 2449 2469 u8 last = 1; 2450 2470 if (dvb_frontend_debug) 2451 2471 printk("%s switch command: 0x%04lx\n", __func__, swcmd); 2452 - do_gettimeofday(&nexttime); 2472 + nexttime = ktime_get_real(); 2453 2473 if (dvb_frontend_debug) 2454 2474 tv[0] = nexttime; 2455 2475 /* before sending a command, initialize by sending ··· 2460 2480 2461 2481 for (i = 0; i < 9; i++) { 2462 2482 if (dvb_frontend_debug) 2463 - do_gettimeofday(&tv[i + 1]); 2483 + tv[i+1] = ktime_get_real(); 2464 2484 if ((swcmd & 0x01) != last) { 2465 2485 /* set voltage to (last ? 13V : 18V) */ 2466 2486 fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18); ··· 2474 2494 printk("%s(%d): switch delay (should be 32k followed by all 8k\n", 2475 2495 __func__, fe->dvb->num); 2476 2496 for (i = 1; i < 10; i++) 2477 - printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); 2497 + printk("%d: %d\n", i, 2498 + (int) ktime_us_delta(tv[i], tv[i-1])); 2478 2499 } 2479 2500 err = 0; 2480 2501 fepriv->state = FESTATE_DISEQC;
+1 -2
drivers/media/dvb-core/dvb_frontend.h
··· 441 441 extern int dvb_frontend_suspend(struct dvb_frontend *fe); 442 442 extern int dvb_frontend_resume(struct dvb_frontend *fe); 443 443 444 - extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec); 445 - extern s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime); 444 + extern void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec); 446 445 447 446 #endif
+7 -5
drivers/media/dvb-frontends/stv0299.c
··· 44 44 45 45 #include <linux/init.h> 46 46 #include <linux/kernel.h> 47 + #include <linux/ktime.h> 47 48 #include <linux/module.h> 48 49 #include <linux/string.h> 49 50 #include <linux/slab.h> ··· 408 407 u8 lv_mask = 0x40; 409 408 u8 last = 1; 410 409 int i; 411 - struct timeval nexttime; 412 - struct timeval tv[10]; 410 + ktime_t nexttime; 411 + ktime_t tv[10]; 413 412 414 413 reg0x08 = stv0299_readreg (state, 0x08); 415 414 reg0x0c = stv0299_readreg (state, 0x0c); ··· 422 421 if (debug_legacy_dish_switch) 423 422 printk ("%s switch command: 0x%04lx\n",__func__, cmd); 424 423 425 - do_gettimeofday (&nexttime); 424 + nexttime = ktime_get_real(); 426 425 if (debug_legacy_dish_switch) 427 426 tv[0] = nexttime; 428 427 stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */ ··· 431 430 432 431 for (i=0; i<9; i++) { 433 432 if (debug_legacy_dish_switch) 434 - do_gettimeofday (&tv[i+1]); 433 + tv[i+1] = ktime_get_real(); 435 434 if((cmd & 0x01) != last) { 436 435 /* set voltage to (last ? 13V : 18V) */ 437 436 stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50)); ··· 447 446 printk ("%s(%d): switch delay (should be 32k followed by all 8k\n", 448 447 __func__, fe->dvb->num); 449 448 for (i = 1; i < 10; i++) 450 - printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); 449 + printk("%d: %d\n", i, 450 + (int) ktime_us_delta(tv[i], tv[i-1])); 451 451 } 452 452 453 453 return 0;