Skip to contentSkip to conversation

eeprom: at25: fix read_poll_timeout() arg order

PATCH In review Ninad Palsule 2 participants 2 messages Oct 15 – Nov 16 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eeprom: at25: fix read_poll_timeout() arg order

The arguments to read_poll_timeout() in at25_wait_ready() are in the wrong order. "false" is passed as sleep_us, while the macro expects sleep_us, timeout_us and sleep_before_read in that order.

This makes the loop busy-poll instead of sleeping 1 ms between reads, and shortens the timeout from EE_TIMEOUT ms to 1 ms, so the wait can fail early.

Pass USEC_PER_MSEC as sleep_us, USEC_PER_MSEC * EE_TIMEOUT as timeout_us, and false as sleep_before_read.

---
 drivers/misc/eeprom/at25.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/eeprom/at25.c +2 -2
index e2868f7bdb03..df8daa40b0e1 100644
@@ -209,9 +209,9 @@ static int at25_wait_ready(struct at25_data *at25)
 					   SPI_MEM_OP_DATA_IN(1, bounce, 1));
 
 	read_poll_timeout(spi_mem_exec_op, status,
-			  status || !(bounce[0] & AT25_SR_nRDY), false,
+			  status || !(bounce[0] & AT25_SR_nRDY),
 			  USEC_PER_MSEC, USEC_PER_MSEC * EE_TIMEOUT,
-			  at25->spimem, &op);
+			  false, at25->spimem, &op);
 	if (status < 0)
 		return status;
 	if (!(bounce[0] & AT25_SR_nRDY))
Signature · 1 line
2.53.0
#1 lore raw

Hi Ninad,

Quoted 7 lines · Ninad Palsule

The arguments to read_poll_timeout() in at25_wait_ready() are in the wrong order. "false" is passed as sleep_us, while the macro expects sleep_us, timeout_us and sleep_before_read in that order.

This makes the loop busy-poll instead of sleeping 1 ms between reads, and shortens the timeout from EE_TIMEOUT ms to 1 ms, so the wait can fail early.

The fail-early behaviour was what you observed? What were the broader impacts? Put another way, what circumstances lead you to discovering the bug? I feel the commit message could benefit from more context there.

Quoted 5 lines

Pass USEC_PER_MSEC as sleep_us, USEC_PER_MSEC * EE_TIMEOUT as timeout_us, and false as sleep_before_read.

I recommend adding a Fixes: tag too.

Quoted 17 lines

---
 drivers/misc/eeprom/at25.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/eeprom/at25.c +0 -0
index e2868f7bdb03..df8daa40b0e1 100644
@@ -209,9 +209,9 @@ static int at25_wait_ready(struct at25_data *at25)
  					   SPI_MEM_OP_DATA_IN(1, bounce, 1));


  read_poll_timeout(spi_mem_exec_op, status,

drivers/misc/eeprom/at25.c +1 -1
-			  status || !(bounce[0] & AT25_SR_nRDY), false,
+			  status || !(bounce[0] & AT25_SR_nRDY),

    USEC_PER_MSEC, USEC_PER_MSEC * EE_TIMEOUT,

drivers/misc/eeprom/at25.c +1 -1
-			  at25->spimem, &op);
+			  false, at25->spimem, &op);
Quoted 3 lines

  if (status < 0)
  return status;
  if (!(bounce[0] & AT25_SR_nRDY))

I can't find that your fix exists upstream.

Can you please send it there first? Then we can backport it once it's accepted.

That said, it looks correct to me.

Andrew