diff mbox series

[v5,02/11] mtd: cfi_cmdset_0002: Remove chip_ready() from do_write_buffer()

Message ID 20190205140759.2360-3-ikegami_to@yahoo.co.jp
State Superseded
Delegated to: Vignesh R
Headers show
Series mtd: cfi_cmdset_0002: Fix flash write issue for OpenWrt Project | expand

Commit Message

Tokunori Ikegami Feb. 5, 2019, 2:07 p.m. UTC
It is enough to use chip_good() only so chip_ready() is not necessary.
Since chip_good() is doing the same check chip_ready() is doing plus an extra
check to make sure we end up with the data we wrote.

For this change the order to check timeout also will be changed at same time.
The order is not a hard requirement, it's just better to avoid the case where
the data update happens just after the timeout has expired.

This change actually a bux that it might cause an infinite loop.
Since currently the infinite loop is only exited by the conditions below.
  1. Timed out and not chip_ready()
  2. chip_good()
So if chip_ready() and not chip_good() the loop is not exited as infinite.

Signed-off-by: Tokunori Ikegami <ikegami_to@yahoo.co.jp>
Fixes: dfeae1073583d ("mtd: cfi_cmdset_0002: Change write buffer to check correct value")
Reported-by: Przemyslaw Sobon <psobon@amazon.com>
Cc: Fabio Bettoni <fbettoni@gmail.com>
Co: Hauke Mehrtens <hauke@hauke-m.de>
Co: Koen Vandeputte <koen.vandeputte@ncentric.com>
Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Cc: linux-mtd@lists.infradead.org
Cc: stable@vger.kernel.org
---
Changes since v4:
- Update the commit message about the infinite loop problem.

Changes since v3:
- Update the commit message for the comment.
- Change the email address of Tokunori Ikegami to ikegami_to@yahoo.co.jp.

Changes since v2:
- None.

Changes since v1:
- None.

 drivers/mtd/chips/cfi_cmdset_0002.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 91a491b..ca9d5fa 100755
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1878,14 +1878,14 @@  static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
 			continue;
 		}
 
-		if (time_after(jiffies, timeo) && !chip_ready(map, adr))
-			break;
-
 		if (chip_good(map, adr, datum)) {
 			xip_enable(map, chip, adr);
 			goto op_done;
 		}
 
+		if (time_after(jiffies, timeo))
+			break;
+
 		/* Latency issues. Drop the lock, wait a while and retry */
 		UDELAY(map, chip, adr, 1);
 	}