Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org
Subject: Re: [PATCH v2] watchdog: make nowayout sysfs file writable
Date: Wed, 6 Nov 2019 06:37:46 -0800
Message-ID: <af10b22d-e609-a216-9cf1-ff564765da58@roeck-us.net> (raw)
In-Reply-To: <20191105205118.11359-1-linux@rasmusvillemoes.dk>

On 11/5/19 12:51 PM, Rasmus Villemoes wrote:
> It can be useful to delay setting the nowayout feature for a watchdog
> device. Moreover, not every driver (notably gpio_wdt) implements a
> nowayout module parameter/otherwise respects CONFIG_WATCHDOG_NOWAYOUT,
> and modifying those drivers carries a risk of causing a regression for
> someone who has two watchdog devices, sets CONFIG_WATCHDOG_NOWAYOUT
> and somehow relies on the gpio_wdt driver being ignorant of
> that (i.e., allowing one to gracefully close a gpio_wdt but not the
> other watchdog in the system).
> 
> So instead, simply make the nowayout sysfs file writable. Obviously,
> setting nowayout is a one-way street.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> v2: drop redundant "current" variable and !!.
> 
>   .../ABI/testing/sysfs-class-watchdog          |  9 ++++++--
>   drivers/watchdog/watchdog_dev.c               | 21 ++++++++++++++++++-
>   2 files changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-watchdog b/Documentation/ABI/testing/sysfs-class-watchdog
> index 675f9b537661..9860a8b2ba75 100644
> --- a/Documentation/ABI/testing/sysfs-class-watchdog
> +++ b/Documentation/ABI/testing/sysfs-class-watchdog
> @@ -17,8 +17,13 @@ What:		/sys/class/watchdog/watchdogn/nowayout
>   Date:		August 2015
>   Contact:	Wim Van Sebroeck <wim@iguana.be>
>   Description:
> -		It is a read only file. While reading, it gives '1' if that
> -		device supports nowayout feature else, it gives '0'.
> +		It is a read/write file. While reading, it gives '1'
> +		if the device has the nowayout feature set, otherwise
> +		it gives '0'. Writing a '1' to the file enables the
> +		nowayout feature. Once set, the nowayout feature
> +		cannot be disabled, so writing a '0' either has no
> +		effect (if the feature was already disabled) or
> +		results in a permission error.
>   
>   What:		/sys/class/watchdog/watchdogn/state
>   Date:		August 2015
> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index dbd2ad4c9294..d3bdcb144657 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -452,7 +452,26 @@ static ssize_t nowayout_show(struct device *dev, struct device_attribute *attr,
>   
>   	return sprintf(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, &wdd->status));
>   }
> -static DEVICE_ATTR_RO(nowayout);
> +
> +static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr,
> +				const char *buf, size_t len)
> +{
> +	struct watchdog_device *wdd = dev_get_drvdata(dev);
> +	unsigned int value;
> +	int ret;
> +
> +	ret = kstrtouint(buf, 0, &value);
> +	if (ret)
> +		return ret;
> +	if (value > 1)
> +		return -EINVAL;
> +	/* nowayout cannot be disabled once set */
> +	if (test_bit(WDOG_NO_WAY_OUT, &wdd->status) && !value)
> +		return -EPERM;
> +	watchdog_set_nowayout(wdd, value);
> +	return len;
> +}
> +static DEVICE_ATTR_RW(nowayout);
>   
>   static ssize_t status_show(struct device *dev, struct device_attribute *attr,
>   				char *buf)
> 


  reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05 12:31 [PATCH] " Rasmus Villemoes
2019-11-05 14:22 ` Guenter Roeck
2019-11-05 20:51 ` [PATCH v2] " Rasmus Villemoes
2019-11-06 14:37   ` Guenter Roeck [this message]
2019-11-05 21:16 ` [PATCH] " kbuild test robot
2019-11-06  7:44   ` Rasmus Villemoes

Reply instructions:

You may reply publically 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=af10b22d-e609-a216-9cf1-ff564765da58@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=wim@linux-watchdog.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

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org
	public-inbox-index linux-watchdog

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git