From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752764AbdDPGLV (ORCPT ); Sun, 16 Apr 2017 02:11:21 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:35119 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751892AbdDPGLT (ORCPT ); Sun, 16 Apr 2017 02:11:19 -0400 Subject: Re: [PATCH v2] watchdog: core: Make use of devm_register_reboot_notifier() To: Andrey Smirnov , linux-watchdog@vger.kernel.org References: <20170411160615.9784-1-andrew.smirnov@gmail.com> Cc: cphealy@gmail.com, linux-kernel@vger.kernel.org, Wim Van Sebroeck , Andy Shevchenko , Andrew Morton From: Guenter Roeck Message-ID: <01843f95-c62f-7844-70ee-eed3dc7d3c23@roeck-us.net> Date: Sat, 15 Apr 2017 23:11:16 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170411160615.9784-1-andrew.smirnov@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: linux@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/11/2017 09:06 AM, Andrey Smirnov wrote: > Save a bit of cleanup code by leveraging newly added > devm_register_reboot_notifier(). > > Cc: cphealy@gmail.com > Cc: linux-kernel@vger.kernel.org > Cc: Wim Van Sebroeck > Cc: Guenter Roeck > Cc: Andy Shevchenko > Cc: Andrew Morton > Signed-off-by: Andrey Smirnov Acked-by: Guenter Roeck > --- > > Guenter, Andy: > > Here's the second version of the patch originally submitted in > [v1]. This time I tried to follow Guenter's suggestion of moving this > bit on initialization in watchdog_dev_register(). > > If I missed something obvious why this patch wouldn't work, again, > please let me know. > > Patch introducting devm_register_reboot_notifier() can be found in > [other-patch] > > Thanks, > Andrey Smirnov > > [v1] https://lkml.org/lkml/2017/4/4/388 > [other-patch] https://lkml.org/lkml/2017/3/20/671 > > > drivers/watchdog/watchdog_core.c | 35 ----------------------------------- > drivers/watchdog/watchdog_dev.c | 32 ++++++++++++++++++++++++++++++++ > 2 files changed, 32 insertions(+), 35 deletions(-) > > diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c > index 74265b2..8a8d952 100644 > --- a/drivers/watchdog/watchdog_core.c > +++ b/drivers/watchdog/watchdog_core.c > @@ -137,25 +137,6 @@ int watchdog_init_timeout(struct watchdog_device *wdd, > } > EXPORT_SYMBOL_GPL(watchdog_init_timeout); > > -static int watchdog_reboot_notifier(struct notifier_block *nb, > - unsigned long code, void *data) > -{ > - struct watchdog_device *wdd = container_of(nb, struct watchdog_device, > - reboot_nb); > - > - if (code == SYS_DOWN || code == SYS_HALT) { > - if (watchdog_active(wdd)) { > - int ret; > - > - ret = wdd->ops->stop(wdd); > - if (ret) > - return NOTIFY_BAD; > - } > - } > - > - return NOTIFY_DONE; > -} > - > static int watchdog_restart_notifier(struct notifier_block *nb, > unsigned long action, void *data) > { > @@ -244,19 +225,6 @@ static int __watchdog_register_device(struct watchdog_device *wdd) > } > } > > - if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) { > - wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; > - > - ret = register_reboot_notifier(&wdd->reboot_nb); > - if (ret) { > - pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", > - wdd->id, ret); > - watchdog_dev_unregister(wdd); > - ida_simple_remove(&watchdog_ida, wdd->id); > - return ret; > - } > - } > - > if (wdd->ops->restart) { > wdd->restart_nb.notifier_call = watchdog_restart_notifier; > > @@ -302,9 +270,6 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd) > if (wdd->ops->restart) > unregister_restart_handler(&wdd->restart_nb); > > - if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) > - unregister_reboot_notifier(&wdd->reboot_nb); > - > watchdog_dev_unregister(wdd); > ida_simple_remove(&watchdog_ida, wdd->id); > } > diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c > index 32930a0..9a52990 100644 > --- a/drivers/watchdog/watchdog_dev.c > +++ b/drivers/watchdog/watchdog_dev.c > @@ -42,6 +42,7 @@ > #include /* For handling misc devices */ > #include /* For module stuff/... */ > #include /* For mutexes */ > +#include /* For reboot notifier */ > #include /* For memory functions */ > #include /* For standard types (like size_t) */ > #include /* For watchdog specific items */ > @@ -998,6 +999,25 @@ static struct class watchdog_class = { > .dev_groups = wdt_groups, > }; > > +static int watchdog_reboot_notifier(struct notifier_block *nb, > + unsigned long code, void *data) > +{ > + struct watchdog_device *wdd = container_of(nb, struct watchdog_device, > + reboot_nb); > + > + if (code == SYS_DOWN || code == SYS_HALT) { > + if (watchdog_active(wdd)) { > + int ret; > + > + ret = wdd->ops->stop(wdd); > + if (ret) > + return NOTIFY_BAD; > + } > + } > + > + return NOTIFY_DONE; > +} > + > /* > * watchdog_dev_register: register a watchdog device > * @wdd: watchdog device > @@ -1031,6 +1051,18 @@ int watchdog_dev_register(struct watchdog_device *wdd) > if (ret) { > device_destroy(&watchdog_class, devno); > watchdog_cdev_unregister(wdd); > + return ret; > + } > + > + if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) { > + wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; > + > + ret = devm_register_reboot_notifier(dev, &wdd->reboot_nb); > + if (ret) { > + pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", > + wdd->id, ret); > + watchdog_dev_unregister(wdd); > + } > } > > return ret; >