The jiffies <= timeout
comparison does not work when the jiffies are wrapping around, so you must use it.
The condition you want to use can be described as "has not yet timed out".
This means that the current time (jiffies
) has not yet reached the timeout time (timeout
), i.e., jiffies
is before the variable you are comparing it to, which means that your variable is after jiffies
.
(All the time_is_
functions have jiffies
on the right side of the comparison.)
So you have to use timer_is_after_jiffies()
in the while
loop.
(And the <=
implies that you actually want to use time_is_after_eq_jiffies()
.)
The timeout check should be better done by reading the GPIO bit, because it would be a shame if your code times out although it got the signal right at the end. Furthermore, busy-looping for a hundred milliseconds is extremly evil; you should release the CPU if you don't need it:
unsigned long timeout = jiffies + msecs_to_jiffies(100);
bool ok = false;
for (;;) {
ok = gpio_bit_read(MPP_CFG_INIT) != 0;
if (ok || time_is_before_eq_jiffies(timeout))
break;
/* you should do msleep(...) or cond_resched() here, if possible */
}
if (!ok) /* timed out? */
...
(This loop uses time_is_before_eq_jiffies()
because the condition is reversed.)