Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0d83679 authored by Sebastian Heutling's avatar Sebastian Heutling Committed by Linus Torvalds
Browse files

eeprom/at25: bugfix "not ready" timeout after write



Under certain circumstances msleep(1) within the loop, which waits for the
EEPROM to be finished, might take longer than the timeout.  On the next
loop the status register might now return to be ready and therefore the
loop finishes.  The following check now tests if a timeout occurred and if
so returns an error although the device reported it was ready.

This fix replaces testing the occurrence of the timeout by testing the
"not ready" bit in the status register.

Signed-off-by: default avatarSebastian Heutling <heutling@who-ing.de>
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 096b7fe0
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -173,6 +173,7 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
		unsigned	segment;
		unsigned	segment;
		unsigned	offset = (unsigned) off;
		unsigned	offset = (unsigned) off;
		u8		*cp = bounce + 1;
		u8		*cp = bounce + 1;
		int		sr;


		*cp = AT25_WREN;
		*cp = AT25_WREN;
		status = spi_write(at25->spi, cp, 1);
		status = spi_write(at25->spi, cp, 1);
@@ -214,7 +215,6 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
		timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
		timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
		retries = 0;
		retries = 0;
		do {
		do {
			int	sr;


			sr = spi_w8r8(at25->spi, AT25_RDSR);
			sr = spi_w8r8(at25->spi, AT25_RDSR);
			if (sr < 0 || (sr & AT25_SR_nRDY)) {
			if (sr < 0 || (sr & AT25_SR_nRDY)) {
@@ -228,7 +228,7 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
				break;
				break;
		} while (retries++ < 3 || time_before_eq(jiffies, timeout));
		} while (retries++ < 3 || time_before_eq(jiffies, timeout));


		if (time_after(jiffies, timeout)) {
		if ((sr < 0) || (sr & AT25_SR_nRDY)) {
			dev_err(&at25->spi->dev,
			dev_err(&at25->spi->dev,
				"write %d bytes offset %d, "
				"write %d bytes offset %d, "
				"timeout after %u msecs\n",
				"timeout after %u msecs\n",