Skip to content

Commit bc44fa7

Browse files
VillemoesWim Van Sebroeck
authored andcommitted
watchdog: make nowayout sysfs file writable
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 <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent a19f893 commit bc44fa7

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Documentation/ABI/testing/sysfs-class-watchdog

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ What: /sys/class/watchdog/watchdogn/nowayout
1717
Date: August 2015
1818
Contact: Wim Van Sebroeck <[email protected]>
1919
Description:
20-
It is a read only file. While reading, it gives '1' if that
21-
device supports nowayout feature else, it gives '0'.
20+
It is a read/write file. While reading, it gives '1'
21+
if the device has the nowayout feature set, otherwise
22+
it gives '0'. Writing a '1' to the file enables the
23+
nowayout feature. Once set, the nowayout feature
24+
cannot be disabled, so writing a '0' either has no
25+
effect (if the feature was already disabled) or
26+
results in a permission error.
2227

2328
What: /sys/class/watchdog/watchdogn/state
2429
Date: August 2015

drivers/watchdog/watchdog_dev.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,26 @@ static ssize_t nowayout_show(struct device *dev, struct device_attribute *attr,
452452

453453
return sprintf(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, &wdd->status));
454454
}
455-
static DEVICE_ATTR_RO(nowayout);
455+
456+
static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr,
457+
const char *buf, size_t len)
458+
{
459+
struct watchdog_device *wdd = dev_get_drvdata(dev);
460+
unsigned int value;
461+
int ret;
462+
463+
ret = kstrtouint(buf, 0, &value);
464+
if (ret)
465+
return ret;
466+
if (value > 1)
467+
return -EINVAL;
468+
/* nowayout cannot be disabled once set */
469+
if (test_bit(WDOG_NO_WAY_OUT, &wdd->status) && !value)
470+
return -EPERM;
471+
watchdog_set_nowayout(wdd, value);
472+
return len;
473+
}
474+
static DEVICE_ATTR_RW(nowayout);
456475

457476
static ssize_t status_show(struct device *dev, struct device_attribute *attr,
458477
char *buf)

0 commit comments

Comments
 (0)