Skip to content

Commit 66aa72c

Browse files
Wolfram SangAndi Shyti
authored andcommitted
i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout()
There is a confusing pattern in the kernel to use a variable named 'timeout' to store the result of wait_for_completion_timeout() causing patterns like: timeout = wait_for_completion_timeout(...) if (!timeout) return -ETIMEDOUT; with all kinds of permutations. Use 'time_left' as a variable to make the code self explaining. Fix to the proper variable type 'unsigned long' while here. Signed-off-by: Wolfram Sang <[email protected]> Acked-by: Paul Cercueil <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent 4259964 commit 66aa72c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/i2c/busses/i2c-jz4780.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static inline int jz4780_i2c_xfer_read(struct jz4780_i2c *i2c,
565565
int idx)
566566
{
567567
int ret = 0;
568-
long timeout;
568+
unsigned long time_left;
569569
int wait_time = JZ4780_I2C_TIMEOUT * (len + 5);
570570
unsigned short tmp;
571571
unsigned long flags;
@@ -600,10 +600,10 @@ static inline int jz4780_i2c_xfer_read(struct jz4780_i2c *i2c,
600600

601601
spin_unlock_irqrestore(&i2c->lock, flags);
602602

603-
timeout = wait_for_completion_timeout(&i2c->trans_waitq,
604-
msecs_to_jiffies(wait_time));
603+
time_left = wait_for_completion_timeout(&i2c->trans_waitq,
604+
msecs_to_jiffies(wait_time));
605605

606-
if (!timeout) {
606+
if (!time_left) {
607607
dev_err(&i2c->adap.dev, "irq read timeout\n");
608608
dev_dbg(&i2c->adap.dev, "send cmd count:%d %d\n",
609609
i2c->cmd, i2c->cmd_buf[i2c->cmd]);
@@ -627,7 +627,7 @@ static inline int jz4780_i2c_xfer_write(struct jz4780_i2c *i2c,
627627
{
628628
int ret = 0;
629629
int wait_time = JZ4780_I2C_TIMEOUT * (len + 5);
630-
long timeout;
630+
unsigned long time_left;
631631
unsigned short tmp;
632632
unsigned long flags;
633633

@@ -655,14 +655,14 @@ static inline int jz4780_i2c_xfer_write(struct jz4780_i2c *i2c,
655655

656656
spin_unlock_irqrestore(&i2c->lock, flags);
657657

658-
timeout = wait_for_completion_timeout(&i2c->trans_waitq,
659-
msecs_to_jiffies(wait_time));
660-
if (timeout && !i2c->stop_hold) {
658+
time_left = wait_for_completion_timeout(&i2c->trans_waitq,
659+
msecs_to_jiffies(wait_time));
660+
if (time_left && !i2c->stop_hold) {
661661
unsigned short i2c_sta;
662662
int write_in_process;
663663

664-
timeout = JZ4780_I2C_TIMEOUT * 100;
665-
for (; timeout > 0; timeout--) {
664+
time_left = JZ4780_I2C_TIMEOUT * 100;
665+
for (; time_left > 0; time_left--) {
666666
i2c_sta = jz4780_i2c_readw(i2c, JZ4780_I2C_STA);
667667

668668
write_in_process = (i2c_sta & JZ4780_I2C_STA_MSTACT) ||
@@ -673,7 +673,7 @@ static inline int jz4780_i2c_xfer_write(struct jz4780_i2c *i2c,
673673
}
674674
}
675675

676-
if (!timeout) {
676+
if (!time_left) {
677677
dev_err(&i2c->adap.dev, "write wait timeout\n");
678678
ret = -EIO;
679679
}

0 commit comments

Comments
 (0)