All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernel/reboot: add devm_register_reboot_notifier
Date: Wed, 29 Mar 2017 16:17:38 -0700	[thread overview]
Message-ID: <20170329161738.ce8c1508f648f9174f0cf8bb@linux-foundation.org> (raw)
In-Reply-To: <20170320171753.1705-1-andrew.smirnov@gmail.com>

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?

  reply	other threads:[~2017-03-29 23:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-20 17:17 [PATCH] kernel/reboot: add devm_register_reboot_notifier Andrey Smirnov
2017-03-29 23:17 ` Andrew Morton [this message]
2017-03-30 22:55   ` Andrey Smirnov
2017-03-30 23:24     ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170329161738.ce8c1508f648f9174f0cf8bb@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andrew.smirnov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.