[PATCH RFC 1/5] kernel/reboot: Deprecate register_restart_handler()

From: Andrew Davis
Date: Fri Nov 17 2023 - 11:10:59 EST


There are now two ways to add a handler to the restart_handler_list.
Two ways to do the same thing is bad design, so let's unify on using
the new method register_sys_off_handler() everywhere.

Reasons:
* The other register_*_handler functions take a callback, this old
API takes a notifier_block, which makes it confusing with the
register_*_notifier class of functions.
* register_sys_off_handler (new API) is a more unified API allowing for
registering several system off types.
* The new API has more helpers built around it now, including devm and
platform helpers.
* The new API manages the struct notifier_block for us, simplifying using
code.

Mark register_restart_handler() as deprecated to try to warn off new users
while we finish converting the remaining existing users.

Signed-off-by: Andrew Davis <afd@xxxxxx>
---
include/linux/reboot.h | 8 ++++++--
kernel/reboot.c | 3 +++
2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index c4cc3b89ced1f..c5fff3157b191 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -46,8 +46,12 @@ extern int unregister_reboot_notifier(struct notifier_block *);

extern int devm_register_reboot_notifier(struct device *, struct notifier_block *);

-extern int register_restart_handler(struct notifier_block *);
-extern int unregister_restart_handler(struct notifier_block *);
+/*
+ * This function is deprecated, use register_sys_off_handler(SYS_OFF_MODE_RESTART)
+ * or devm_register_restart_handler() instead.
+ */
+extern int __deprecated register_restart_handler(struct notifier_block *);
+extern int __deprecated unregister_restart_handler(struct notifier_block *);
extern void do_kernel_restart(char *cmd);

/*
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 395a0ea3c7a8a..768ce97829f41 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -189,6 +189,9 @@ static ATOMIC_NOTIFIER_HEAD(restart_handler_list);
*
* Currently always returns zero, as atomic_notifier_chain_register()
* always returns zero.
+ *
+ * This function is deprecated, use register_sys_off_handler(SYS_OFF_MODE_RESTART)
+ * or devm_register_restart_handler() instead.
*/
int register_restart_handler(struct notifier_block *nb)
{
--
2.39.2