Skip to content

Commit 7a5b764

Browse files
Martin Fuzzeygregkh
authored andcommitted
w1: mxc_w1: Fix timeout resolution problem leading to bus error
commit c972375 upstream. On my platform (i.MX53) bus access sometimes fails with w1_search: max_slave_count 64 reached, will continue next search. The reason is the use of jiffies to implement a 200us timeout in mxc_w1_ds2_touch_bit(). On some platforms the jiffies timer resolution is insufficient for this. Fix by replacing jiffies by ktime_get(). For consistency apply the same change to the other use of jiffies in mxc_w1_ds2_reset_bus(). Fixes: f80b258 ("w1: mxc_w1: Optimize mxc_w1_ds2_touch_bit()") Cc: stable <stable@vger.kernel.org> Signed-off-by: Martin Fuzzey <martin.fuzzey@flowbird.group> Link: https://lore.kernel.org/r/1601455030-6607-1-git-send-email-martin.fuzzey@flowbird.group Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0c399a6 commit 7a5b764

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

drivers/w1/masters/mxc_w1.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <linux/clk.h>
88
#include <linux/delay.h>
99
#include <linux/io.h>
10-
#include <linux/jiffies.h>
10+
#include <linux/ktime.h>
1111
#include <linux/module.h>
1212
#include <linux/mod_devicetable.h>
1313
#include <linux/platform_device.h>
@@ -40,12 +40,12 @@ struct mxc_w1_device {
4040
static u8 mxc_w1_ds2_reset_bus(void *data)
4141
{
4242
struct mxc_w1_device *dev = data;
43-
unsigned long timeout;
43+
ktime_t timeout;
4444

4545
writeb(MXC_W1_CONTROL_RPP, dev->regs + MXC_W1_CONTROL);
4646

4747
/* Wait for reset sequence 511+512us, use 1500us for sure */
48-
timeout = jiffies + usecs_to_jiffies(1500);
48+
timeout = ktime_add_us(ktime_get(), 1500);
4949

5050
udelay(511 + 512);
5151

@@ -55,7 +55,7 @@ static u8 mxc_w1_ds2_reset_bus(void *data)
5555
/* PST bit is valid after the RPP bit is self-cleared */
5656
if (!(ctrl & MXC_W1_CONTROL_RPP))
5757
return !(ctrl & MXC_W1_CONTROL_PST);
58-
} while (time_is_after_jiffies(timeout));
58+
} while (ktime_before(ktime_get(), timeout));
5959

6060
return 1;
6161
}
@@ -68,12 +68,12 @@ static u8 mxc_w1_ds2_reset_bus(void *data)
6868
static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit)
6969
{
7070
struct mxc_w1_device *dev = data;
71-
unsigned long timeout;
71+
ktime_t timeout;
7272

7373
writeb(MXC_W1_CONTROL_WR(bit), dev->regs + MXC_W1_CONTROL);
7474

7575
/* Wait for read/write bit (60us, Max 120us), use 200us for sure */
76-
timeout = jiffies + usecs_to_jiffies(200);
76+
timeout = ktime_add_us(ktime_get(), 200);
7777

7878
udelay(60);
7979

@@ -83,7 +83,7 @@ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit)
8383
/* RDST bit is valid after the WR1/RD bit is self-cleared */
8484
if (!(ctrl & MXC_W1_CONTROL_WR(bit)))
8585
return !!(ctrl & MXC_W1_CONTROL_RDST);
86-
} while (time_is_after_jiffies(timeout));
86+
} while (ktime_before(ktime_get(), timeout));
8787

8888
return 0;
8989
}

0 commit comments

Comments
 (0)