[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211007060253.17049-4-digetx@gmail.com>
Date: Thu, 7 Oct 2021 09:02:50 +0300
From: Dmitry Osipenko <digetx@...il.com>
To: Thierry Reding <thierry.reding@...il.com>,
Jonathan Hunter <jonathanh@...dia.com>,
Lee Jones <lee.jones@...aro.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Mark Brown <broonie@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Guenter Roeck <linux@...ck-us.net>,
Russell King <linux@...linux.org.uk>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Ulf Hansson <ulf.hansson@...aro.org>
Cc: linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-tegra@...r.kernel.org
Subject: [PATCH v1 3/6] kernel: Add devm_register_restart_handler()
Add resource-managed variant of register_restart_handler().
Signed-off-by: Dmitry Osipenko <digetx@...il.com>
---
include/linux/reboot.h | 2 ++
kernel/reboot.c | 27 +++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index f72fb8729608..fb17fad63e53 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -49,6 +49,8 @@ extern int register_restart_handler(struct notifier_block *);
extern int unregister_restart_handler(struct notifier_block *);
extern void do_kernel_restart(char *cmd);
+extern int devm_register_restart_handler(struct device *, struct notifier_block *);
+
extern int register_poweroff_handler(struct notifier_block *);
extern int unregister_poweroff_handler(struct notifier_block *);
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 6e90afec2bb8..b611e49a5ac6 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -200,6 +200,33 @@ int unregister_restart_handler(struct notifier_block *nb)
}
EXPORT_SYMBOL(unregister_restart_handler);
+static void devm_unregister_restart_handler(struct device *dev, void *res)
+{
+ WARN_ON(unregister_restart_handler(*(struct notifier_block **)res));
+}
+
+int devm_register_restart_handler(struct device *dev, struct notifier_block *nb)
+{
+ struct notifier_block **rcnb;
+ int ret;
+
+ rcnb = devres_alloc(devm_unregister_restart_handler,
+ sizeof(*rcnb), GFP_KERNEL);
+ if (!rcnb)
+ return -ENOMEM;
+
+ ret = register_restart_handler(nb);
+ if (!ret) {
+ *rcnb = nb;
+ devres_add(dev, rcnb);
+ } else {
+ devres_free(rcnb);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(devm_register_restart_handler);
+
/**
* do_kernel_restart - Execute kernel restart handler call chain
*
--
2.32.0
Powered by blists - more mailing lists