* [PATCH] kernel/reboot: add devm_register_reboot_notifier
@ 2017-03-20 17:17 Andrey Smirnov
2017-03-29 23:17 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Andrey Smirnov @ 2017-03-20 17:17 UTC (permalink / raw)
To: linux-kernel; +Cc: Andrey Smirnov, Andrew Morton
Add devm_* wrapper around register_reboot_notifier to simplify device
specific reboot notifier registration/unregistration.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
include/linux/reboot.h | 3 +++
kernel/reboot.c | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index a7ff409..0ca2541 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -38,6 +38,9 @@ extern int reboot_force;
extern int register_reboot_notifier(struct notifier_block *);
extern int unregister_reboot_notifier(struct notifier_block *);
+struct device;
+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 *);
extern void do_kernel_restart(char *cmd);
diff --git a/kernel/reboot.c b/kernel/reboot.c
index bd30a97..e4ced88 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -104,6 +104,33 @@ int unregister_reboot_notifier(struct notifier_block *nb)
}
EXPORT_SYMBOL(unregister_reboot_notifier);
+static void devm_unregister_reboot_notifier(struct device *dev, void *res)
+{
+ WARN_ON(unregister_reboot_notifier(*(struct notifier_block **)res));
+}
+
+int devm_register_reboot_notifier(struct device *dev, struct notifier_block *nb)
+{
+ struct notifier_block **rcnb;
+ int ret;
+
+ rcnb = devres_alloc(devm_unregister_reboot_notifier,
+ sizeof(*rcnb), GFP_KERNEL);
+ if (!rcnb)
+ return -ENOMEM;
+
+ ret = register_reboot_notifier(nb);
+ if (!ret) {
+ *rcnb = nb;
+ devres_add(dev, rcnb);
+ } else {
+ devres_free(rcnb);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(devm_register_reboot_notifier);
+
/*
* Notifier list for kernel code which wants to be called
* to restart the system.
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kernel/reboot: add devm_register_reboot_notifier
2017-03-20 17:17 [PATCH] kernel/reboot: add devm_register_reboot_notifier Andrey Smirnov
@ 2017-03-29 23:17 ` Andrew Morton
2017-03-30 22:55 ` Andrey Smirnov
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2017-03-29 23:17 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: linux-kernel
On Mon, 20 Mar 2017 10:17:53 -0700 Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> Add devm_* wrapper around register_reboot_notifier to simplify device
> specific reboot notifier registration/unregistration.
>
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -104,6 +104,33 @@ int unregister_reboot_notifier(struct notifier_block *nb)
> }
> EXPORT_SYMBOL(unregister_reboot_notifier);
>
> +static void devm_unregister_reboot_notifier(struct device *dev, void *res)
> +{
> + WARN_ON(unregister_reboot_notifier(*(struct notifier_block **)res));
> +}
> +
> +int devm_register_reboot_notifier(struct device *dev, struct notifier_block *nb)
> +{
> + struct notifier_block **rcnb;
> + int ret;
> +
> + rcnb = devres_alloc(devm_unregister_reboot_notifier,
> + sizeof(*rcnb), GFP_KERNEL);
> + if (!rcnb)
> + return -ENOMEM;
> +
> + ret = register_reboot_notifier(nb);
> + if (!ret) {
> + *rcnb = nb;
> + devres_add(dev, rcnb);
> + } else {
> + devres_free(rcnb);
> + }
> +
> + return ret;
> +}
> +EXPORT_SYMBOL(devm_register_reboot_notifier);
Seems reasonable. Can we please have some patches which actually use
this?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kernel/reboot: add devm_register_reboot_notifier
2017-03-29 23:17 ` Andrew Morton
@ 2017-03-30 22:55 ` Andrey Smirnov
2017-03-30 23:24 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Andrey Smirnov @ 2017-03-30 22:55 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, Chris Healy
On Wed, Mar 29, 2017 at 4:17 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Mon, 20 Mar 2017 10:17:53 -0700 Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
>
>> Add devm_* wrapper around register_reboot_notifier to simplify device
>> specific reboot notifier registration/unregistration.
>>
>> --- a/kernel/reboot.c
>> +++ b/kernel/reboot.c
>> @@ -104,6 +104,33 @@ int unregister_reboot_notifier(struct notifier_block *nb)
>> }
>> EXPORT_SYMBOL(unregister_reboot_notifier);
>>
>> +static void devm_unregister_reboot_notifier(struct device *dev, void *res)
>> +{
>> + WARN_ON(unregister_reboot_notifier(*(struct notifier_block **)res));
>> +}
>> +
>> +int devm_register_reboot_notifier(struct device *dev, struct notifier_block *nb)
>> +{
>> + struct notifier_block **rcnb;
>> + int ret;
>> +
>> + rcnb = devres_alloc(devm_unregister_reboot_notifier,
>> + sizeof(*rcnb), GFP_KERNEL);
>> + if (!rcnb)
>> + return -ENOMEM;
>> +
>> + ret = register_reboot_notifier(nb);
>> + if (!ret) {
>> + *rcnb = nb;
>> + devres_add(dev, rcnb);
>> + } else {
>> + devres_free(rcnb);
>> + }
>> +
>> + return ret;
>> +}
>> +EXPORT_SYMBOL(devm_register_reboot_notifier);
>
> Seems reasonable. Can we please have some patches which actually use
> this?
I will be submitting a serdev/watchdog driver in next couple of weeks,
I can CC you on that thread.
Thanks,
Andrey Smirnov
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kernel/reboot: add devm_register_reboot_notifier
2017-03-30 22:55 ` Andrey Smirnov
@ 2017-03-30 23:24 ` Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2017-03-30 23:24 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: linux-kernel, Chris Healy
On Thu, 30 Mar 2017 15:55:43 -0700 Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> On Wed, Mar 29, 2017 at 4:17 PM, Andrew Morton
> <akpm@linux-foundation.org> wrote:
> > On Mon, 20 Mar 2017 10:17:53 -0700 Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> >
> >> Add devm_* wrapper around register_reboot_notifier to simplify device
> >> specific reboot notifier registration/unregistration.
> >>
> >> --- a/kernel/reboot.c
> >> +++ b/kernel/reboot.c
> >> @@ -104,6 +104,33 @@ int unregister_reboot_notifier(struct notifier_block *nb)
> >> }
> >> EXPORT_SYMBOL(unregister_reboot_notifier);
> >>
> >> +static void devm_unregister_reboot_notifier(struct device *dev, void *res)
> >> +{
> >> + WARN_ON(unregister_reboot_notifier(*(struct notifier_block **)res));
> >> +}
> >> +
> >> +int devm_register_reboot_notifier(struct device *dev, struct notifier_block *nb)
> >> +{
> >> + struct notifier_block **rcnb;
> >> + int ret;
> >> +
> >> + rcnb = devres_alloc(devm_unregister_reboot_notifier,
> >> + sizeof(*rcnb), GFP_KERNEL);
> >> + if (!rcnb)
> >> + return -ENOMEM;
> >> +
> >> + ret = register_reboot_notifier(nb);
> >> + if (!ret) {
> >> + *rcnb = nb;
> >> + devres_add(dev, rcnb);
> >> + } else {
> >> + devres_free(rcnb);
> >> + }
> >> +
> >> + return ret;
> >> +}
> >> +EXPORT_SYMBOL(devm_register_reboot_notifier);
> >
> > Seems reasonable. Can we please have some patches which actually use
> > this?
>
> I will be submitting a serdev/watchdog driver in next couple of weeks,
> I can CC you on that thread.
It would be nice to convert some other call sites as well, please - at
least to get additional test coverage and to demonstrate the usefulness
of the new interface.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-30 23:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-20 17:17 [PATCH] kernel/reboot: add devm_register_reboot_notifier Andrey Smirnov
2017-03-29 23:17 ` Andrew Morton
2017-03-30 22:55 ` Andrey Smirnov
2017-03-30 23:24 ` Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.