From patchwork Wed May 25 13:47:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 9135407 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5918C607D9 for ; Wed, 25 May 2016 13:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49F5B27EE9 for ; Wed, 25 May 2016 13:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EE59282DC; Wed, 25 May 2016 13:48:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDED127EE9 for ; Wed, 25 May 2016 13:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754347AbcEYNsF (ORCPT ); Wed, 25 May 2016 09:48:05 -0400 Received: from sauhun.de ([89.238.76.85]:36457 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754307AbcEYNsD (ORCPT ); Wed, 25 May 2016 09:48:03 -0400 Received: from dslb-178-008-084-178.178.008.pools.vodafone-ip.de ([178.8.84.178]:46622 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1b5ZAH-0007iM-2D; Wed, 25 May 2016 15:48:01 +0200 From: Wolfram Sang To: linux-watchdog@vger.kernel.org Cc: Wolfram Sang , linux-renesas-soc@vger.kernel.org, Guenter Roeck , Vladimir Zapolskiy Subject: [RFC 1/2] watchdog: dev: add helper for creating uevent on dev Date: Wed, 25 May 2016 15:47:41 +0200 Message-Id: <1464184062-5230-2-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464184062-5230-1-git-send-email-wsa@the-dreams.de> References: <1464184062-5230-1-git-send-email-wsa@the-dreams.de> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wolfram Sang Mechanisms like pretimeout governors may want to notify userspace via uevents. Add a helper because all the needed data is private to the watchdog device. To allow calling it in atomic contexts, put actual signalling to a workqueue. Signed-off-by: Wolfram Sang --- drivers/watchdog/watchdog_dev.c | 20 ++++++++++++++++++++ include/linux/watchdog.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 9e2e668e1c6b2d..2a7d04034641dc 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -63,6 +63,7 @@ struct watchdog_core_data { struct kref kref; struct cdev cdev; struct watchdog_device *wdd; + struct device *dev; struct mutex lock; unsigned long last_keepalive; unsigned long last_hw_keepalive; @@ -70,6 +71,7 @@ struct watchdog_core_data { unsigned long status; /* Internal status bits */ #define _WDOG_DEV_OPEN 0 /* Opened ? */ #define _WDOG_ALLOW_RELEASE 1 /* Did we receive the magic char ? */ + struct work_struct uevent_work; }; /* the dev_t structure to store the dynamically allocated watchdog devices */ @@ -821,6 +823,21 @@ static struct miscdevice watchdog_miscdev = { .fops = &watchdog_fops, }; +void watchdog_dev_uevent(struct watchdog_device *wdd) +{ + queue_work(watchdog_wq, &wdd->wd_data->uevent_work); +} + +static void watchdog_dev_uevent_work(struct work_struct *work) +{ + struct watchdog_core_data *wd_data = container_of(work, struct watchdog_core_data, + uevent_work); + + mutex_lock(&wd_data->lock); + kobject_uevent(&wd_data->dev->kobj, KOBJ_CHANGE); + mutex_unlock(&wd_data->lock); +} + /* * watchdog_cdev_register: register watchdog character device * @wdd: watchdog device @@ -849,6 +866,7 @@ static int watchdog_cdev_register(struct watchdog_device *wdd, dev_t devno) return -ENODEV; INIT_DELAYED_WORK(&wd_data->work, watchdog_ping_work); + INIT_WORK(&wd_data->uevent_work, watchdog_dev_uevent_work); if (wdd->id == 0) { old_wd_data = wd_data; @@ -968,6 +986,8 @@ int watchdog_dev_register(struct watchdog_device *wdd) watchdog_cdev_unregister(wdd); } + wdd->wd_data->dev = dev; + return ret; } diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 496e52e5b91fc7..f0f77f06d9813b 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -194,6 +194,9 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, extern int watchdog_register_device(struct watchdog_device *); extern void watchdog_unregister_device(struct watchdog_device *); +/* drivers/watchdog/watchdog_dev.c */ +void watchdog_dev_uevent(struct watchdog_device *wdd); + /* drivers/watchdog/watchdog_pretimeout.c */ #ifdef CONFIG_WATCHDOG_PRETIMEOUT_GOV void watchdog_notify_pretimeout(struct watchdog_device *wdd);