Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp717638ybx; Tue, 5 Nov 2019 04:33:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwMluC3xIyjIVK+vQeYs6gXT1ws3Uob+dMCWiv4SuHOJHi/VjeQsrK7X/CZvZa9dt0V8Xqb X-Received: by 2002:a50:8dc5:: with SMTP id s5mr35360751edh.115.1572957188775; Tue, 05 Nov 2019 04:33:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572957188; cv=none; d=google.com; s=arc-20160816; b=DHHHXlhPX1viFz7UPTSsT4098VqT/RMb1c6slxlj+x8iHV+tPilXWIRz2rFs3nENDC /+158oczbEX9tMNUIzfN5bVvY3eBiR7eYFeD7Jd1NmjYhA/mBa+XwpZ537eoBNTVF4QI 4FnhrxDI8YgRmmfwOxwJqNCPtvUqWTXBCP+JGNTCK3ghj9LLaEA/X5bWMQxNyl1i7rpR 3KhSHigA6bZgD8b6q3JEnZ3JYYGgX0rYVZ4C/JvvADY1ddGQi2ecBwmXCG4TwqT2Gyzq dwV7Rj+qN1LPwruODWgiN45Ry0VasLVLiGe2ym83xir98NcfzpDWt9VGTk4iuqmLo3xA xCjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kMRRzBdYGAmjCi84Oik+o1hEPde0vMlLbqwfzhBep3Y=; b=m8Jn/zuVzZqNORzULj5KYDwEoGkkaL7q3qfn/1RzWdMTBnj8OqP/T9l+642d0ffQ+s ZNvKieVWeeFh1h71oiInj7V9SuZbn4Kid3JiZAg78HKAdqtbnrwDKzx5yGyu5OlLhjcL eL9q9e7EYztPlS6UVViwwnW7fVYbBu7R7edGsKjoPlDpNGCad0f3junV5qp36JBlXa5L nfaefR8GYUSHCcf45fq31dpjz2vpR5fnwXcCKnRw2Php6Lymaph0vaMjr7OxCv6OqrsJ ZgLqZumWs3ShyGvwofVzJfRd8jmBrUlobJkVmPCjRioIEtA0aPUe7v2jx7R9WWP/DTvQ lNMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=TLkHehXC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id la4si13713164ejb.145.2019.11.05.04.32.45; Tue, 05 Nov 2019 04:33:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=TLkHehXC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388222AbfKEMbd (ORCPT + 99 others); Tue, 5 Nov 2019 07:31:33 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:39758 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387744AbfKEMbd (ORCPT ); Tue, 5 Nov 2019 07:31:33 -0500 Received: by mail-lf1-f65.google.com with SMTP id 195so14959086lfj.6 for ; Tue, 05 Nov 2019 04:31:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kMRRzBdYGAmjCi84Oik+o1hEPde0vMlLbqwfzhBep3Y=; b=TLkHehXCoUaUGstiwdj8fjVlz9gpUtcPChFOwjxmUtGkFfOi0uQ7WwBFH9q99o2YaS RyO+Ddp4ujrXZoIKDYOx4TOi+TqY9Mu5qkwdw83/3cvXoJW63WcWkgO+D01XxbKUhkNa HyqFjL7lLvZ6HfbuTZdSE0DCCBUUTUCRDluvU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kMRRzBdYGAmjCi84Oik+o1hEPde0vMlLbqwfzhBep3Y=; b=hXPSU3LtrB+G/XL2fO9x8jOHxIv0zDGCqcyC+IJFneZ1QozcbMnUAvCnmhvmazrao/ gTrfE24RvGlRapcw9N1KWrtkzMG0zxUs/Ikgzkqv1HSkERjaF9paFLHnBfiqsPrY8Owt AibFewGPpNgySnM7yVb6oYdjYI5bHB86LEsB6VXN6DLl0GAXrMsp6SyAbmgZkVVfB/8d 2acBfqi7q3nBndhMc098iO6s14ugE0OJLMZTBuGGemJ9JhC4/+utlQHh5DF36sQu7Kbl bphIMr/+gMJQB7myXV57QZU/EmsDYm6Rngxs/c4JJwyMNtzBVUApjkEu4MMyNt5N7o1i LCuQ== X-Gm-Message-State: APjAAAWrSL0m9jQWPsxsfM1WnoSF4wGNTggIgITf6FDD/yxW9iB+Fizo 4Er/2womloNAPg6i7sbfBHQDAN8C4AkYcg== X-Received: by 2002:ac2:4856:: with SMTP id 22mr19654061lfy.131.1572957089421; Tue, 05 Nov 2019 04:31:29 -0800 (PST) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id i128sm10953245lfd.6.2019.11.05.04.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 04:31:28 -0800 (PST) From: Rasmus Villemoes To: Wim Van Sebroeck , Guenter Roeck Cc: Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org Subject: [PATCH] watchdog: make nowayout sysfs file writable Date: Tue, 5 Nov 2019 13:31:25 +0100 Message-Id: <20191105123125.25985-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- .../ABI/testing/sysfs-class-watchdog | 9 ++++++-- drivers/watchdog/watchdog_dev.c | 22 ++++++++++++++++++- 2 files changed, 28 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 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..0c478b8f8d5a 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -452,7 +452,27 @@ 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, current; + int ret; + + ret = kstrtouint(buf, 0, &value); + if (ret) + return ret; + if (value > 1) + return -EINVAL; + current = !!test_bit(WDOG_NO_WAY_OUT, &wdd->status); + /* nowayout cannot be disabled once set */ + if (current && !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) -- 2.23.0