aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Brezillon <[email protected]>2020-05-18 17:52:37 +0200
committerMiquel Raynal <[email protected]>2020-05-24 20:39:50 +0200
commite45a4b652dbd2f8b5a3b8e97e89f602a58cb28aa (patch)
tree9acd6e680d0ee95bdadd6cd9cb2468167887165b
parentdbf15080ff2d0656304acb9595ecd8397f17b36d (diff)
mtd: rawnand: Fix nand_gpio_waitrdy()
Mimic what's done in nand_soft_waitrdy() and add one to the jiffies timeout so we don't end up waiting less than actually required. Reported-by: Tudor Ambarus <[email protected]> Fixes: b0e137ad24b6c ("mtd: rawnand: Provide helper for polling GPIO R/B pin") Cc: <[email protected]> Signed-off-by: Boris Brezillon <[email protected]> Reviewed-by: Tudor Ambarus <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
-rw-r--r--drivers/mtd/nand/raw/nand_base.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index c4d6d5482b31..79e8052bdff9 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -790,8 +790,14 @@ EXPORT_SYMBOL_GPL(nand_soft_waitrdy);
int nand_gpio_waitrdy(struct nand_chip *chip, struct gpio_desc *gpiod,
unsigned long timeout_ms)
{
- /* Wait until R/B pin indicates chip is ready or timeout occurs */
- timeout_ms = jiffies + msecs_to_jiffies(timeout_ms);
+
+ /*
+ * Wait until R/B pin indicates chip is ready or timeout occurs.
+ * +1 below is necessary because if we are now in the last fraction
+ * of jiffy and msecs_to_jiffies is 1 then we will wait only that
+ * small jiffy fraction - possibly leading to false timeout.
+ */
+ timeout_ms = jiffies + msecs_to_jiffies(timeout_ms) + 1;
do {
if (gpiod_get_value_cansleep(gpiod))
return 0;