mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] nvmem: rockchip-otp: skip zero-byte reads
@ 2026-06-18  4:08 Ruoyu Wang
  2026-07-16 21:21 ` Srinivas Kandagatla
  0 siblings, 1 reply; 2+ messages in thread
From: Ruoyu Wang @ 2026-06-18  4:08 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Heiko Stuebner, Jonas Karlman, linux-arm-kernel, linux-rockchip,
	linux-kernel, Ruoyu Wang

nvmem_device_read() does not reject a zero-byte read before calling the
provider reg_read callback. rockchip_otp_read() then enables clocks and
dispatches to the SoC-specific callback.

Return 0 from rockchip_otp_read() before enabling clocks when bytes is
zero. This avoids hardware access for empty reads and prevents zero
counts from reaching the internal reg_read callbacks.

Fixes: 8ab099fafbbc ("nvmem: rockchip-otp: Add support for RK3588")
Suggested-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
v2:
- Handle empty reads in rockchip_otp_read() instead of initializing ret in
  rk3588_otp_read().

 drivers/nvmem/rockchip-otp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvmem/rockchip-otp.c b/drivers/nvmem/rockchip-otp.c
index 0ec78b5e19e7d..95685a9fcc77b 100644
--- a/drivers/nvmem/rockchip-otp.c
+++ b/drivers/nvmem/rockchip-otp.c
@@ -272,6 +272,9 @@ static int rockchip_otp_read(void *context, unsigned int offset,
 	if (!otp->data || !otp->data->reg_read)
 		return -EINVAL;
 
+	if (!bytes)
+		return 0;
+
 	ret = clk_bulk_prepare_enable(otp->data->num_clks, otp->clks);
 	if (ret < 0) {
 		dev_err(otp->dev, "failed to prepare/enable clks\n");
-- 
2.51.0

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

* Re: [PATCH v2] nvmem: rockchip-otp: skip zero-byte reads
  2026-06-18  4:08 [PATCH v2] nvmem: rockchip-otp: skip zero-byte reads Ruoyu Wang
@ 2026-07-16 21:21 ` Srinivas Kandagatla
  0 siblings, 0 replies; 2+ messages in thread
From: Srinivas Kandagatla @ 2026-07-16 21:21 UTC (permalink / raw)
  To: Ruoyu Wang, Srinivas Kandagatla
  Cc: Heiko Stuebner, Jonas Karlman, linux-arm-kernel, linux-rockchip,
	linux-kernel



On 6/18/26 5:08 AM, Ruoyu Wang wrote:
> nvmem_device_read() does not reject a zero-byte read before calling the
> provider reg_read callback. rockchip_otp_read() then enables clocks and
> dispatches to the SoC-specific callback.
> 

if the core does not do this check then the check belongs in the core
not in individual providers.

--srini
> Return 0 from rockchip_otp_read() before enabling clocks when bytes is
> zero. This avoids hardware access for empty reads and prevents zero
> counts from reaching the internal reg_read callbacks.
> 
> Fixes: 8ab099fafbbc ("nvmem: rockchip-otp: Add support for RK3588")
> Suggested-by: Jonas Karlman <jonas@kwiboo.se>
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
> ---
> v2:
> - Handle empty reads in rockchip_otp_read() instead of initializing ret in
>   rk3588_otp_read().
> 
>  drivers/nvmem/rockchip-otp.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/nvmem/rockchip-otp.c b/drivers/nvmem/rockchip-otp.c
> index 0ec78b5e19e7d..95685a9fcc77b 100644
> --- a/drivers/nvmem/rockchip-otp.c
> +++ b/drivers/nvmem/rockchip-otp.c
> @@ -272,6 +272,9 @@ static int rockchip_otp_read(void *context, unsigned int offset,
>  	if (!otp->data || !otp->data->reg_read)
>  		return -EINVAL;
>  
> +	if (!bytes)
> +		return 0;
> +
>  	ret = clk_bulk_prepare_enable(otp->data->num_clks, otp->clks);
>  	if (ret < 0) {
>  		dev_err(otp->dev, "failed to prepare/enable clks\n");


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

end of thread, other threads:[~2026-07-16 21:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-18  4:08 [PATCH v2] nvmem: rockchip-otp: skip zero-byte reads Ruoyu Wang
2026-07-16 21:21 ` Srinivas Kandagatla

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