eeprom: at25: fix read_poll_timeout() arg order
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
@@ -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
Hi Ninad,
Quoted 7 lines · Ninad Palsule
The arguments to
read_poll_timeout()inat25_wait_ready()are in the wrong order. "false" is passed assleep_us, while the macro expectssleep_us,timeout_usandsleep_before_readin that order.This makes the loop busy-poll instead of sleeping 1 ms between reads, and shortens the timeout from
EE_TIMEOUTms 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_MSECassleep_us,USEC_PER_MSEC*EE_TIMEOUTastimeout_us, and false assleep_before_read.Signed-off-by Ninad Palsule <[email protected]>
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@@ -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