mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] power: reset: syscon-reboot: Use devm_register_sys_off_handler(RESTART)
@ 2026-10-26  9:20 David Yang
  2026-11-09  1:23 ` Sebastian Reichel
  2026-11-25 17:28 ` Miguel Ojeda
  0 siblings, 2 replies; 3+ messages in thread
From: David Yang @ 2026-10-26  9:20 UTC (permalink / raw)
  To: linux-pm; +Cc: David Yang, Sebastian Reichel, Feng Kan, linux-kernel

The driver registers its restart handler but never unregisters it:
there is no remove callback and the notifier block lives in the
devm-allocated context. After unbind the freed notifier stays on the
handler list and the next reboot oopses on it, observed on a
Hi3798MV100 board (PC is at 0x0, LR is at notifier_call_chain).

Use the device-managed registration, which unregisters the handler on
driver unbind; the DT-configured priority is passed through. This
mirrors the conversion of the syscon-poweroff sibling.

Fixes: 09fb07bcaf52 ("power: reset: Add generic SYSCON register mapped reset")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/power/reset/syscon-reboot.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/power/reset/syscon-reboot.c b/drivers/power/reset/syscon-reboot.c
index 60e855cae68e..348a9550e9e3 100644
--- a/drivers/power/reset/syscon-reboot.c
+++ b/drivers/power/reset/syscon-reboot.c
@@ -31,16 +31,12 @@ struct syscon_reboot_context {
 
 	const struct reboot_data *rd; /* from of match data, if any */
 	struct reboot_mode_bits catchall; /* from DT */
-
-	struct notifier_block restart_handler;
 };
 
-static int syscon_restart_handle(struct notifier_block *this,
-					unsigned long mode, void *cmd)
+static int syscon_restart_handle(struct sys_off_data *data)
 {
-	struct syscon_reboot_context *ctx =
-			container_of(this, struct syscon_reboot_context,
-					restart_handler);
+	struct syscon_reboot_context *ctx = data->cb_data;
+	unsigned int mode = data->mode;
 	const struct reboot_mode_bits *mode_bits;
 
 	if (ctx->rd) {
@@ -113,11 +109,11 @@ static int syscon_reboot_probe(struct platform_device *pdev)
 		}
 	}
 
-	ctx->restart_handler.notifier_call = syscon_restart_handle;
-	ctx->restart_handler.priority = priority;
-	err = register_restart_handler(&ctx->restart_handler);
+	err = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART,
+					    priority, syscon_restart_handle,
+					    ctx);
 	if (err)
-		dev_err(dev, "can't register restart notifier (err=%d)\n", err);
+		dev_err(dev, "can't register restart handler (err=%d)\n", err);
 
 	return err;
 }
-- 
2.53.0


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

* Re: [PATCH] power: reset: syscon-reboot: Use devm_register_sys_off_handler(RESTART)
  2026-10-26  9:20 [PATCH] power: reset: syscon-reboot: Use devm_register_sys_off_handler(RESTART) David Yang
@ 2026-11-09  1:23 ` Sebastian Reichel
  2026-11-25 17:28 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2026-11-09  1:23 UTC (permalink / raw)
  To: linux-pm, David Yang; +Cc: Sebastian Reichel, Feng Kan, linux-kernel


On Mon, 26 Oct 2026 17:20:47 +0800, David Yang wrote:
> The driver registers its restart handler but never unregisters it:
> there is no remove callback and the notifier block lives in the
> devm-allocated context. After unbind the freed notifier stays on the
> handler list and the next reboot oopses on it, observed on a
> Hi3798MV100 board (PC is at 0x0, LR is at notifier_call_chain).
> 
> Use the device-managed registration, which unregisters the handler on
> driver unbind; the DT-configured priority is passed through. This
> mirrors the conversion of the syscon-poweroff sibling.
> 
> [...]

Applied, thanks!

[1/1] power: reset: syscon-reboot: Use devm_register_sys_off_handler(RESTART)
      commit: 808914f0c0141a5e0bd66e13daff7f9d2aa12155

Best regards,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>


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

* Re: [PATCH] power: reset: syscon-reboot: Use devm_register_sys_off_handler(RESTART)
  2026-10-26  9:20 [PATCH] power: reset: syscon-reboot: Use devm_register_sys_off_handler(RESTART) David Yang
  2026-11-09  1:23 ` Sebastian Reichel
@ 2026-11-25 17:28 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2026-11-25 17:28 UTC (permalink / raw)
  To: mmyangfl; +Cc: fkan, linux-kernel, linux-pm, sre, Aurelien Jarno, Anand Moon

On Mon, 26 Oct 2026 17:20:47 +0800 David Yang <mmyangfl@gmail.com> wrote:
>
> +	err = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART,
> +					    priority, syscon_restart_handle,
> +					    ctx);

In linux-next (next-20261123), booting riscv64 under QEMU, I am seeing:

    syscon-reboot reboot: can't register restart handler (err=-16)
    syscon-reboot reboot: probe with driver syscon-reboot failed with error -16

My LLM says:

  The SBI SRST restart handler (`sbi_srst_reboot_nb`) is already registered
  at priority 192, which is also the default one for this driver, and
  `register_sys_off_handler()` only allows one handler per non-default
  priority, unlike `register_restart_handler()`.

  The following patch moves the SBI one to `SYS_OFF_PRIO_FIRMWARE`, and
  with both patches on top of v7.4-rc4 the driver probes again:

    https://lore.kernel.org/all/20261118104935.1716-2-linux.amoon@gmail.com/

Cc'ing Anand and Aurelien.

I hope that helps!

Cheers,
Miguel

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

end of thread, other threads:[~2026-11-25 17:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26  9:20 [PATCH] power: reset: syscon-reboot: Use devm_register_sys_off_handler(RESTART) David Yang
2026-11-09  1:23 ` Sebastian Reichel
2026-11-25 17:28 ` Miguel Ojeda

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

all inboxes | Powered by JetHome®