Re: [PATCH] media: si21xx: use time_after_eq() instead of jiffies judgment

From: Joe Perches
Date: Thu Feb 10 2022 - 04:07:27 EST


On Thu, 2022-02-10 at 00:31 -0800, Qing Wang wrote:
> From: Wang Qing <wangqing@xxxxxxxx>
>
> It is better to use time_xxx() directly instead of jiffies judgment
> for understanding.
[]
> diff --git a/drivers/media/dvb-frontends/si21xx.c b/drivers/media/dvb-frontends/si21xx.c
[]
> @@ -336,7 +336,7 @@ static int si21xx_wait_diseqc_idle(struct si21xx_state *state, int timeout)
> dprintk("%s\n", __func__);
>
> while ((si21_readreg(state, LNB_CTRL_REG_1) & 0x8) == 8) {
> - if (jiffies - start > timeout) {
> + if (time_after(jiffies, start + timeout)) {
> dprintk("%s: timeout!!\n", __func__);
> return -ETIMEDOUT;
> }

Appreciate all the conversions (IMO it should have been sent as
a block of patches with a cover letter instead of independent
unrelated patches) but wouldn't all of these be simpler and more
consistent using a style where the addition is done once and the
timeout test is something like:

unsigned long end = jiffies + timeout;

while (foo) {
if (time_after(jiffies, end)) {
error_msg(...)
return -ETIMEDOUT;
}
bar...;
}