From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756238AbcFGRl1 (ORCPT ); Tue, 7 Jun 2016 13:41:27 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:39252 "EHLO relay1.mentorg.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756079AbcFGRi6 (ORCPT ); Tue, 7 Jun 2016 13:38:58 -0400 From: Vladimir Zapolskiy To: Wim Van Sebroeck , Guenter Roeck CC: Wolfram Sang , Robin Gong , , Subject: [PATCH v3 2/6] watchdog: add WDIOC_SETPRETIMEOUT and WDIOC_GETPRETIMEOUT Date: Tue, 7 Jun 2016 20:38:43 +0300 Message-ID: <1465321127-19522-3-git-send-email-vladimir_zapolskiy@mentor.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1465321127-19522-1-git-send-email-vladimir_zapolskiy@mentor.com> References: <1465321127-19522-1-git-send-email-vladimir_zapolskiy@mentor.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [137.202.0.76] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Gong Since the watchdog common framework centrialize the IOCTL interfaces of device driver now, the SETPRETIMEOUT and GETPRETIMEOUT need to be added in common code. Signed-off-by: Robin Gong [vzapolskiy: rebased, cleanups] Signed-off-by: Vladimir Zapolskiy --- Changes from v2 to v3: * none, new change Changes from v1 to v2: * none, new change drivers/watchdog/watchdog_dev.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 3595cff..42ab86d 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -318,6 +318,27 @@ static int watchdog_set_timeout(struct watchdog_device *wdd, } /* + * watchdog_set_pretimeout: set the watchdog timer pretimeout + * @wdd: the watchdog device to set the timeout for + * @timeout: pretimeout to set in seconds + * + * The caller must hold wd_data->lock. + */ + +static int watchdog_set_pretimeout(struct watchdog_device *wdd, + unsigned int pretimeout) +{ + if (!wdd->ops->set_pretimeout || + !(wdd->info->options & WDIOF_PRETIMEOUT)) + return -EOPNOTSUPP; + + if (watchdog_pretimeout_invalid(wdd, pretimeout)) + return -EINVAL; + + return wdd->ops->set_pretimeout(wdd, pretimeout); +} + +/* * watchdog_get_timeleft: wrapper to get the time left before a reboot * @wdd: the watchdog device to get the remaining time from * @timeleft: the time that's left @@ -620,6 +641,16 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, break; err = put_user(val, p); break; + case WDIOC_SETPRETIMEOUT: + if (get_user(val, p)) { + err = -EFAULT; + break; + } + err = watchdog_set_pretimeout(wdd, val); + break; + case WDIOC_GETPRETIMEOUT: + err = put_user(wdd->pretimeout, p); + break; default: err = -ENOTTY; break; -- 2.5.0