mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
@ 2026-11-27 14:21 Kristian Otnes (kotnes)
  2026-11-27 20:33 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Kristian Otnes (kotnes) @ 2026-11-27 14:21 UTC (permalink / raw)
  To: brgl; +Cc: bibby.hsieh, das, linux-kernel, srini, stable, das

This is ONLY a check for a detail on this patch, in case it has not been considered. It is not intended as a vote against the patch:

The at24 driver is presumably very old and was designed in a way with checking if eeprom is accessible BEFORE reading or writing. That takes care of the delayed internal write process. One can speculate why this approach was used, but it does avoid delays on occasional writes, since no wait added after final byte/page write, and potentially completed on next later access. The question is, should that concept be changed by now always adding a wait after a write?

The subtle problem documented for causing this patch was caused by the PM support added much later. If one wants to keep the original at24 design behavior, maybe one should look into how PM support to driver is handled. Either look into if PM autosuspend can be used or possibly only add a delay/polling if the device is under PM management (ie consumer registered or something).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
  2026-11-27 14:21 [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM Kristian Otnes (kotnes)
@ 2026-11-27 20:33 ` Greg KH
  2026-11-29 10:14   ` Kristian Otnes (kotnes)
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2026-11-27 20:33 UTC (permalink / raw)
  To: Kristian Otnes (kotnes)
  Cc: brgl, bibby.hsieh, das, linux-kernel, srini, stable

On Fri, Nov 27, 2026 at 02:21:26PM +0000, Kristian Otnes (kotnes) wrote:
> This is ONLY a check for a detail on this patch, in case it has not been considered. It is not intended as a vote against the patcha

There is no context here :(

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
  2026-11-27 20:33 ` Greg KH
@ 2026-11-29 10:14   ` Kristian Otnes (kotnes)
  2026-11-29 12:17     ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Kristian Otnes (kotnes) @ 2026-11-29 10:14 UTC (permalink / raw)
  To: Greg KH; +Cc: brgl, bibby.hsieh, das, linux-kernel, srini, stable

Hi Greg,

Greg wrote:
> There is no context here :(

I apologize that my previous message lacked context and was poorly
formatted.

I am referring to Daniel's email of 26 November 2026, with the subject
"[PATCH] eeprom: at24: wait for write cycle before releasing runtime PM".

The patch reads the last written byte before releasing the runtime PM
reference. This uses the driver's existing retry mechanism to wait for
the EEPROM to respond.

My question is about the behavior and trade-off, rather than an
objection to fixing the reported data-loss case.

The driver is based on the principle of retries prior to write or
read in case the EEPROM is still busy with a previous write cycle.

One possible reason for this behavior is to avoid making the
caller wait for the final write cycle. This may have been an
intentional latency optimization. The proposed change would
keep at24_write() from returning successfully until the final write
cycle completes. Is that an acceptable trade-off for the suggested
patch?

Could this failure instead be addressed in the runtime PM handling?
Since it was introduced by adding runtime PM support, autosuspend
could preserve the driver's existing write behavior. For example,
the autosuspend delay could be set to at24_write_timeout, with
at24_write() using pm_runtime_put_autosuspend(). If this seems
preferable, that alternative would require a new patch proposal
with additional runtime PM changes to configure and use autosuspend.

Regards,
Kristian

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
  2026-11-29 10:14   ` Kristian Otnes (kotnes)
@ 2026-11-29 12:17     ` Greg KH
  2026-11-29 14:11       ` Kristian Otnes (kotnes)
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2026-11-29 12:17 UTC (permalink / raw)
  To: Kristian Otnes (kotnes)
  Cc: brgl, bibby.hsieh, das, linux-kernel, srini, stable

On Sun, Nov 29, 2026 at 10:14:00AM +0000, Kristian Otnes (kotnes) wrote:
> Hi Greg,
> 
> Greg wrote:
> > There is no context here :(
> 
> I apologize that my previous message lacked context and was poorly
> formatted.
> 
> I am referring to Daniel's email of 26 November 2026, with the subject
> "[PATCH] eeprom: at24: wait for write cycle before releasing runtime PM".
> 
> The patch reads the last written byte before releasing the runtime PM
> reference. This uses the driver's existing retry mechanism to wait for
> the EEPROM to respond.
> 
> My question is about the behavior and trade-off, rather than an
> objection to fixing the reported data-loss case.

Then please quote the email properly, don't expect us to be able to look
it up somehow.  Everything you need us to respond to should be in the
email itself.

Remember, some of us get 1000+ emails a day.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
  2026-11-29 12:17     ` Greg KH
@ 2026-11-29 14:11       ` Kristian Otnes (kotnes)
  0 siblings, 0 replies; 7+ messages in thread
From: Kristian Otnes (kotnes) @ 2026-11-29 14:11 UTC (permalink / raw)
  To: Greg KH; +Cc: brgl, bibby.hsieh, das, linux-kernel, srini, stable


On Sun, 29 Nov 2026 13:17:49 +0100, Greg KH wrote:
> Then please quote the email properly, don't expect us to be able to look
> it up somehow.  Everything you need us to respond to should be in the
> email itself.

My apologies again. I really don't want to disturb you unnecessary with
this detail. Hope the following is sufficient.

On Thu, 26 Nov 2026 01:15:35 +0100, Daniel Svendsen wrote:
> at24_regmap_write() returns as soon as the chip has ACKed the
> transfer, but the EEPROM only programs the data afterwards, during its
> internal write cycle (typically up to 5 ms). For all but the last
> chunk, the following write is NACKed and retried until that cycle has
> finished. After the last chunk nothing waits, and at24_write() drops
> its runtime PM reference right away. When vcc is controlled through
> runtime PM and has no other users, at24_suspend() disables the
> regulator in the middle of the write cycle and the last chunk is lost,
> while the write is reported as successful.
>
> This was seen on a board where the EEPROM supply is a switchable
> regulator used only by at24: 32-byte writes with a 16-byte page size
> programmed just the first 16 bytes.
>
> Wait for the write cycle to finish before releasing runtime PM by
> doing a one-byte read of the last written address. at24_regmap_read()
> retries while the chip NACKs, up to write_timeout.
>
> Fixes: cd5676db0574 ("misc: eeprom: at24: support pm_runtime control")
> Cc: stable@vger.kernel.org
> Signed-off-by: Daniel Svendsen <das@emlogic.no>
> ---
>  drivers/nvmem/at24.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvmem/at24.c b/drivers/nvmem/at24.c
> index b9db13cc3e33..03cd83e5caff 100644
> --- a/drivers/nvmem/at24.c
> +++ b/drivers/nvmem/at24.c
> @@ -482,6 +482,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>  	struct at24_data *at24;
>  	struct device *dev;
>  	char *buf = val;
> +	char dummy;
>  	int ret;
>
>  	at24 = priv;
> @@ -514,11 +515,17 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>  		count -= ret;
>  	}
>
> +	/*
> +	 * Wait for the last chunk's internal write cycle to finish before
> +	 * dropping the runtime PM reference, which may switch off vcc.
> +	 */
> +	ret = at24_regmap_read(at24, &dummy, off - 1, 1);
> +
>  	mutex_unlock(&at24->lock);
>
>  	pm_runtime_put(dev);
>
> -	return 0;
> +	return ret < 0 ? ret : 0;
>  }
>
>  static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,

The patch reads the last written byte before releasing the runtime PM
reference. This uses the driver's existing retry mechanism to wait for
the EEPROM to respond.

My question is about the behavior and trade-off, rather than an
objection to fixing the reported data-loss case.

The driver is based on the principle of retries prior to write or
read in case the EEPROM is still busy with a previous write cycle.

One possible reason for this behavior is to avoid making the
caller wait for the final write cycle. This may have been an
intentional latency optimization. The proposed change would
keep at24_write() from returning successfully until the final write
cycle completes. Is that an acceptable trade-off for the suggested
patch?

Could this failure instead be addressed in the runtime PM handling?
Since it was introduced by later adding runtime PM support, autosuspend
could preserve the driver's existing write behavior. For example,
the autosuspend delay could be set to at24_write_timeout, with
at24_write() using pm_runtime_put_autosuspend(). If this seems
preferable, that alternative would require a new patch proposal
with additional runtime PM changes to configure and use autosuspend.

Thanks,
Kristian

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
  2026-11-26  0:15 Daniel Svendsen via B4 Relay
@ 2026-11-26 14:58 ` Bartosz Golaszewski
  0 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2026-11-26 14:58 UTC (permalink / raw)
  To: Daniel Svendsen; +Cc: Srinivas Kandagatla, Bibby Hsieh, linux-kernel, stable

On Thu, Nov 26, 2026 at 01:15:35AM +0100, Daniel Svendsen wrote:
> at24_regmap_write() returns as soon as the chip has ACKed the
> transfer, but the EEPROM only programs the data afterwards, during its
> internal write cycle (typically up to 5 ms). For all but the last
> chunk, the following write is NACKed and retried until that cycle has
> finished. After the last chunk nothing waits, and at24_write() drops
> its runtime PM reference right away. When vcc is controlled through
> runtime PM and has no other users, at24_suspend() disables the
> regulator in the middle of the write cycle and the last chunk is lost,
> while the write is reported as successful.
> 
> This was seen on a board where the EEPROM supply is a switchable
> regulator used only by at24: 32-byte writes with a 16-byte page size
> programmed just the first 16 bytes.
> 
> Wait for the write cycle to finish before releasing runtime PM by
> doing a one-byte read of the last written address. at24_regmap_read()
> retries while the chip NACKs, up to write_timeout.
> 
> Fixes: cd5676db0574 ("misc: eeprom: at24: support pm_runtime control")
> Cc: stable@vger.kernel.org
> Signed-off-by: Daniel Svendsen <das@emlogic.no>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
@ 2026-11-26  0:15 Daniel Svendsen via B4 Relay
  2026-11-26 14:58 ` Bartosz Golaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Svendsen via B4 Relay @ 2026-11-26  0:15 UTC (permalink / raw)
  To: Bartosz Golaszewski, Srinivas Kandagatla
  Cc: Bibby Hsieh, linux-kernel, stable, Daniel Svendsen

From: Daniel Svendsen <das@emlogic.no>

at24_regmap_write() returns as soon as the chip has ACKed the
transfer, but the EEPROM only programs the data afterwards, during its
internal write cycle (typically up to 5 ms). For all but the last
chunk, the following write is NACKed and retried until that cycle has
finished. After the last chunk nothing waits, and at24_write() drops
its runtime PM reference right away. When vcc is controlled through
runtime PM and has no other users, at24_suspend() disables the
regulator in the middle of the write cycle and the last chunk is lost,
while the write is reported as successful.

This was seen on a board where the EEPROM supply is a switchable
regulator used only by at24: 32-byte writes with a 16-byte page size
programmed just the first 16 bytes.

Wait for the write cycle to finish before releasing runtime PM by
doing a one-byte read of the last written address. at24_regmap_read()
retries while the chip NACKs, up to write_timeout.

Fixes: cd5676db0574 ("misc: eeprom: at24: support pm_runtime control")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Svendsen <das@emlogic.no>
---
 drivers/nvmem/at24.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/at24.c b/drivers/nvmem/at24.c
index b9db13cc3e33..03cd83e5caff 100644
--- a/drivers/nvmem/at24.c
+++ b/drivers/nvmem/at24.c
@@ -482,6 +482,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
 	struct at24_data *at24;
 	struct device *dev;
 	char *buf = val;
+	char dummy;
 	int ret;
 
 	at24 = priv;
@@ -514,11 +515,17 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
 		count -= ret;
 	}
 
+	/*
+	 * Wait for the last chunk's internal write cycle to finish before
+	 * dropping the runtime PM reference, which may switch off vcc.
+	 */
+	ret = at24_regmap_read(at24, &dummy, off - 1, 1);
+
 	mutex_unlock(&at24->lock);
 
 	pm_runtime_put(dev);
 
-	return 0;
+	return ret < 0 ? ret : 0;
 }
 
 static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,

---
base-commit: ebb7a8dc1e74c705daffe11c2faf38ec2628f838
change-id: 20261126-at24-write-cycle-7cedfd00f9f2

Best regards,
--  
Daniel Svendsen <das@emlogic.no>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-29 14:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 14:21 [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM Kristian Otnes (kotnes)
2026-11-27 20:33 ` Greg KH
2026-11-29 10:14   ` Kristian Otnes (kotnes)
2026-11-29 12:17     ` Greg KH
2026-11-29 14:11       ` Kristian Otnes (kotnes)
  -- strict thread matches above, loose matches on Subject: below --
2026-11-26  0:15 Daniel Svendsen via B4 Relay
2026-11-26 14:58 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®