From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933057AbdC2XRl (ORCPT ); Wed, 29 Mar 2017 19:17:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:40888 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753026AbdC2XRk (ORCPT ); Wed, 29 Mar 2017 19:17:40 -0400 Date: Wed, 29 Mar 2017 16:17:38 -0700 From: Andrew Morton To: Andrey Smirnov Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel/reboot: add devm_register_reboot_notifier Message-Id: <20170329161738.ce8c1508f648f9174f0cf8bb@linux-foundation.org> In-Reply-To: <20170320171753.1705-1-andrew.smirnov@gmail.com> References: <20170320171753.1705-1-andrew.smirnov@gmail.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 20 Mar 2017 10:17:53 -0700 Andrey Smirnov 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?