On 2/13/26 06:27, Aswin Murugan wrote:
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 <[email protected]>
---
  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 = {

I'm not sure about this. drivers/power/reset/nvmem-reboot-mode.c in Linux
always writes sizeof(unsigned long), and this is checked against the nvmem
cell length in __nvmem_cell_entry_write. We should try to keep our behavior
close to Linux's.

--Sean

Reply via email to