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

Input: hil_mlc - convert timeval to jiffies

struct timeval is not y2038 safe, and what mlc->instart do is
scheduling a task in a fixed timeout, so jiffies is the
simplest choice here.

In hilse_donode(), the expires in mod_timer equals

jiffies + intimeout - (now - instart)

If we use jiffies in 'now', the expires equals

instart + intimeout

So, all we need to do is that making sure expires is a future
timestamp before passed it to mod_timer.

[arnd: slightly simplified patch further]

Link: https://lists.linaro.org/pipermail/y2038/2015-October/000937.html
Signed-off-by: WEN Pingbo <pingbo.wen@linaro.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Patchwork-Id: 10076615
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

WEN Pingbo and committed by
Dmitry Torokhov
59d805af ac45e629

+10 -17
+7 -11
drivers/input/serio/hil_mlc.c
··· 602 602 BUG(); 603 603 } 604 604 mlc->istarted = 1; 605 - mlc->intimeout = node->arg; 606 - do_gettimeofday(&(mlc->instart)); 605 + mlc->intimeout = usecs_to_jiffies(node->arg); 606 + mlc->instart = jiffies; 607 607 mlc->icount = 15; 608 608 memset(mlc->ipacket, 0, 16 * sizeof(hil_packet)); 609 609 BUG_ON(down_trylock(&mlc->isem)); ··· 708 708 break; 709 709 } 710 710 mlc->ostarted = 0; 711 - do_gettimeofday(&(mlc->instart)); 711 + mlc->instart = jiffies; 712 712 write_unlock_irqrestore(&mlc->lock, flags); 713 713 nextidx = HILSEN_NEXT; 714 714 break; ··· 729 729 #endif 730 730 731 731 while (nextidx & HILSEN_SCHED) { 732 - struct timeval tv; 732 + unsigned long now = jiffies; 733 733 734 734 if (!sched_long) 735 735 goto sched; 736 736 737 - do_gettimeofday(&tv); 738 - tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); 739 - tv.tv_usec -= mlc->instart.tv_usec; 740 - if (tv.tv_usec >= mlc->intimeout) goto sched; 741 - tv.tv_usec = (mlc->intimeout - tv.tv_usec) * HZ / USEC_PER_SEC; 742 - if (!tv.tv_usec) goto sched; 743 - mod_timer(&hil_mlcs_kicker, jiffies + tv.tv_usec); 737 + if (time_after(now, mlc->instart + mlc->intimeout)) 738 + goto sched; 739 + mod_timer(&hil_mlcs_kicker, mlc->instart + mlc->intimeout); 744 740 break; 745 741 sched: 746 742 tasklet_schedule(&hil_mlcs_tasklet);
+1 -4
drivers/input/serio/hp_sdc_mlc.c
··· 149 149 150 150 /* Try to down the semaphore */ 151 151 if (down_trylock(&mlc->isem)) { 152 - struct timeval tv; 153 152 if (priv->emtestmode) { 154 153 mlc->ipacket[0] = 155 154 HIL_ERR_INT | (mlc->opacket & ··· 159 160 /* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */ 160 161 goto wasup; 161 162 } 162 - do_gettimeofday(&tv); 163 - tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); 164 - if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) { 163 + if (time_after(jiffies, mlc->instart + mlc->intimeout)) { 165 164 /* printk("!%i %i", 166 165 tv.tv_usec - mlc->instart.tv_usec, 167 166 mlc->intimeout);
+2 -2
include/linux/hil_mlc.h
··· 144 144 hil_packet ipacket[16]; 145 145 hil_packet imatch; 146 146 int icount; 147 - struct timeval instart; 148 - suseconds_t intimeout; 147 + unsigned long instart; 148 + unsigned long intimeout; 149 149 150 150 int ddi; /* Last operational device id */ 151 151 int lcv; /* LCV to throttle loops */