From d2b3d4f45d43e20e5cb70943fa1cd3c23148411d Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 10 Mar 2022 22:12:07 +0100 Subject: power: reset: reboot-mode: Fix resetting to normal mode To clear the reboot mode for next reboot during registration of a reboot mode driver we call reboot->write() with a zero initialized u32 array with a single entry. This is wrong for two reasons. First the array is too short, for i.MX6 we need to entries. Then it is assumed that the magic to write to the register is '0' for normal boot, but it could be an arbitrary value. To fix this pick the index of the normal boot entry and pass the corresponding magic values to reboot->write(). While at it only do this when a normal boot entry actually exists. Signed-off-by: Sascha Hauer Link: https://lore.barebox.org/20220310211207.3949118-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer --- drivers/power/reset/reboot-mode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c index d9b51dfea6..01709e0019 100644 --- a/drivers/power/reset/reboot-mode.c +++ b/drivers/power/reset/reboot-mode.c @@ -127,7 +127,7 @@ int reboot_mode_register(struct reboot_mode_driver *reboot, const char *alias; size_t nmodes = 0; int i = 0; - int ret; + int ret, normal = -1; for_each_property_of_node(np, prop) { u32 magic; @@ -171,6 +171,9 @@ int reboot_mode_register(struct reboot_mode_driver *reboot, goto error; } + if (!strcmp(*mode, "normal")) + normal = i; + reboot_mode_print(reboot, *mode, magic); i++; @@ -187,7 +190,8 @@ int reboot_mode_register(struct reboot_mode_driver *reboot, reboot_mode_add_param(reboot->dev, "", reboot); /* clear mode for next reboot */ - reboot->write(reboot, &(u32) { 0 }); + if (normal >= 0) + reboot->write(reboot, &reboot->magics[normal]); if (!reboot->priority) reboot->priority = REBOOT_MODE_DEFAULT_PRIORITY; -- cgit v1.2.3