Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1249197ybx; Tue, 5 Nov 2019 12:55:03 -0800 (PST) X-Google-Smtp-Source: APXvYqzkAKVX23fpmZZ4Xl2wSlOytiEI+K9tkWmUGVMLHU7GQwu3SEBrvatRt/9ARHMlp7jYrO/k X-Received: by 2002:a50:bac2:: with SMTP id x60mr20465117ede.114.1572987303062; Tue, 05 Nov 2019 12:55:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572987303; cv=none; d=google.com; s=arc-20160816; b=xcxzjDom3x4pHSbYLZVKfe1+84wyDXOY6fjNsDLhhgymVPX1+lfXUsjHFNryviFAYk XGI95djikDn0do3LaxErAYILhzRyU1uWg3lNBrjl+zHuFY4zPBHBGQvn++XWSyz0GStD FMmjdp3uvrNmH15B90uk+M3UBpUYd+xBFLY83c6UZIT3owPJBQ1m+W4cUUj3tSQYccsj 4SDbZFSqeERnEuOqa8qA/7/mnxQYiayFj/2bow8YjTfpDcnCWIeFlqST+Wcfvj6j9+Nv GTIF8iunzkahLE6GXXtZ2ZYifA0I0qjdPPKlxhTEHC2gOVn3vRNBHc6FATlKym2718SI pKBw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=86+b3nLS9bc8VDStO93HdimlizslTYlGrlQhHJTbrT4=; b=mZWtZOaFXp0jfzhafYeYOYPGB/EPhqKmYSYZvBHbVueJpHzUANCwVYaF4ByPto67DM IVYl1wx07IVdcg8JBbrW0WVtixuRFV3jH/FghSduaPpJRN3/ODJokGRoOmJASUcB3xzJ USo+4Kl/X/CJ6mpvkcthGyogZ3RHjPGh2H5UWts8/T6IpOD/ZQeQj6FHpP80Y2CUZ24Q efcSsSSOkmcfL8yBc2j+a3vCeFSi8AsldIVbAwM9bGvUWoKjCTDsswP8dnmC7qTdexfn ZBpc3xM0+d7fkY65pX1Ca0KwhRK0n6bCL+Q/Xz+nI5zqUL8dQuo4C7xwlXOaP8D7rXdK CvaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=VsXcQfps; 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 b30si11167411edc.320.2019.11.05.12.54.39; Tue, 05 Nov 2019 12:55:03 -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=VsXcQfps; 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 S1729839AbfKEUvZ (ORCPT + 99 others); Tue, 5 Nov 2019 15:51:25 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51502 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725806AbfKEUvZ (ORCPT ); Tue, 5 Nov 2019 15:51:25 -0500 Received: by mail-wm1-f65.google.com with SMTP id q70so908872wme.1 for ; Tue, 05 Nov 2019 12:51:23 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=86+b3nLS9bc8VDStO93HdimlizslTYlGrlQhHJTbrT4=; b=VsXcQfpstDMDBiO/7BvB/yl0oN780/GG/FJehxFtBv77wAHaYRFX8xW5lDSq2WHLlS 8RF/ARYHZfN5KAqvNgA91kSpzufz7c/zI/5GhNR34FdUiNTmFDlOvRAxt/jEz7Xc18fQ F3+4wE6qJOQtYYHS6cz5on9mOT+NI+HGGhjDI= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=86+b3nLS9bc8VDStO93HdimlizslTYlGrlQhHJTbrT4=; b=Psc6cwvBehT6QCh96zkjX/UgqVsiYHWL72vfH0uuuK71yOFDZgOQ2e6kX6EQMQY0tj Vv0NkXYvx8o3qTXUz9iCfW+Rd7rvS7AIMQSuYZnH4ClyPLX89t6TQB0PFvvZvuBOqFOK Cxo60Y/t4J25d4OkoAvGYaclLNPZxdJOIdTnRuUxbx9G57mqQQwsxrKpZ8hbYZt3Hpup tE/3DqxxXZOtFCJG18PnUN289i1cp7U9uQUNBVqg9VWRkh1BxxbiRR+5IRGjyupY+knw HrE7CmvjWQymM8sZBv3tS8pkwSyICmLPX2pFiPt+dxZoi3R68Hu6VbxaBm8M3SHJF6Y0 vqPQ== X-Gm-Message-State: APjAAAUnVyruqAO5XvmqYxUg/iJrfZXssKHiWsmLIPIvdaxaf3+ly7Ij QlATeWfqNVnK2nWhwoRZITCGFA== X-Received: by 2002:a1c:e0c4:: with SMTP id x187mr797441wmg.93.1572987082645; Tue, 05 Nov 2019 12:51:22 -0800 (PST) Received: from prevas-ravi.prevas.se (ip-5-186-115-54.cgn.fibianet.dk. [5.186.115.54]) by smtp.gmail.com with ESMTPSA id 4sm690226wmd.33.2019.11.05.12.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 12:51:21 -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 v2] watchdog: make nowayout sysfs file writable Date: Tue, 5 Nov 2019 21:51:18 +0100 Message-Id: <20191105205118.11359-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191105123125.25985-1-linux@rasmusvillemoes.dk> References: <20191105123125.25985-1-linux@rasmusvillemoes.dk> 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 --- 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 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) -- 2.23.0