[PATCH v2 1/6] reboot-mode: Use actual cell size instead of sizeof(u32)

Aswin Murugan aswin.murugan at oss.qualcomm.com
Fri Feb 13 12:27:12 CET 2026


The nvmem reboot-mode driver hardcodes sizeof(u32) for NVMEM read/write
operations. This fails on platforms where the reboot reason storage is
smaller than 4 bytes.

On Qualcomm platforms with single-byte PMIC register storage, attempting
to read 4 bytes from a 1-byte cell causes the NVMEM subsystem to return
-EINVAL, breaking reboot-mode functionality.

Replace sizeof(*mode) and sizeof(mode) with priv->cell.size to use the
actual NVMEM cell size. Also initialize *mode to 0 in reboot_mode_get()
to ensure a clean state for cells smaller than u32.

This allows the driver to work with cells of any size, from single bytes
to multi-byte words.

Signed-off-by: Aswin Murugan <aswin.murugan at oss.qualcomm.com>
---
 drivers/reboot-mode/reboot-mode-nvmem.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/reboot-mode/reboot-mode-nvmem.c b/drivers/reboot-mode/reboot-mode-nvmem.c
index b9af242520a..60307cce49f 100644
--- a/drivers/reboot-mode/reboot-mode-nvmem.c
+++ b/drivers/reboot-mode/reboot-mode-nvmem.c
@@ -18,15 +18,16 @@ struct nvmem_reboot_mode_priv {
 static int reboot_mode_get(struct udevice *dev, u32 *mode)
 {
 	struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
+	*mode = 0;
 
-	return nvmem_cell_read(&priv->cell, mode, sizeof(*mode));
+	return nvmem_cell_read(&priv->cell, mode, priv->cell.size);
 }
 
 static int reboot_mode_set(struct udevice *dev, u32 mode)
 {
 	struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
 
-	return nvmem_cell_write(&priv->cell, &mode, sizeof(mode));
+	return nvmem_cell_write(&priv->cell, &mode, priv->cell.size);
 }
 
 static const struct reboot_mode_ops nvmem_reboot_mode_ops = {
-- 
2.34.1



More information about the U-Boot mailing list