Skip to contentSkip to conversation

nvmem: rockchip-otp: skip zero-byte reads

PATCH In review Ruoyu Wang 2 participants 2 messages Jun 18 – Jul 16

Subsystems (2)
lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH v2 1/1 nvmem: rockchip-otp: skip zero-byte reads

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")

---
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(+)
drivers/nvmem/rockchip-otp.c +3 -0
index 0ec78b5e19e7d..95685a9fcc77b 100644
@@ -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");
Signature · 1 line
2.51.0
#1 lore raw
Quoted 4 lines · 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.

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

--srini

Quoted 29 lines

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")

---
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(+)
drivers/nvmem/rockchip-otp.c +3 -0
index 0ec78b5e19e7d..95685a9fcc77b 100644
@@ -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");