Skip to content

Commit 59d805a

Browse files
WEN Pingbodtor
authored andcommitted
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 <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]> Patchwork-Id: 10076615 Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent ac45e62 commit 59d805a

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

drivers/input/serio/hil_mlc.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node
602602
BUG();
603603
}
604604
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;
607607
mlc->icount = 15;
608608
memset(mlc->ipacket, 0, 16 * sizeof(hil_packet));
609609
BUG_ON(down_trylock(&mlc->isem));
@@ -708,7 +708,7 @@ static int hilse_donode(hil_mlc *mlc)
708708
break;
709709
}
710710
mlc->ostarted = 0;
711-
do_gettimeofday(&(mlc->instart));
711+
mlc->instart = jiffies;
712712
write_unlock_irqrestore(&mlc->lock, flags);
713713
nextidx = HILSEN_NEXT;
714714
break;
@@ -729,18 +729,14 @@ static int hilse_donode(hil_mlc *mlc)
729729
#endif
730730

731731
while (nextidx & HILSEN_SCHED) {
732-
struct timeval tv;
732+
unsigned long now = jiffies;
733733

734734
if (!sched_long)
735735
goto sched;
736736

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);
744740
break;
745741
sched:
746742
tasklet_schedule(&hil_mlcs_tasklet);

drivers/input/serio/hp_sdc_mlc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)
149149

150150
/* Try to down the semaphore */
151151
if (down_trylock(&mlc->isem)) {
152-
struct timeval tv;
153152
if (priv->emtestmode) {
154153
mlc->ipacket[0] =
155154
HIL_ERR_INT | (mlc->opacket &
@@ -160,9 +159,7 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)
160159
/* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */
161160
goto wasup;
162161
}
163-
do_gettimeofday(&tv);
164-
tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec);
165-
if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) {
162+
if (time_after(jiffies, mlc->instart + mlc->intimeout)) {
166163
/* printk("!%i %i",
167164
tv.tv_usec - mlc->instart.tv_usec,
168165
mlc->intimeout);

include/linux/hil_mlc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ struct hil_mlc {
144144
hil_packet ipacket[16];
145145
hil_packet imatch;
146146
int icount;
147-
struct timeval instart;
148-
suseconds_t intimeout;
147+
unsigned long instart;
148+
unsigned long intimeout;
149149

150150
int ddi; /* Last operational device id */
151151
int lcv; /* LCV to throttle loops */

0 commit comments

Comments
 (0)