Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp915253pxa; Wed, 19 Aug 2020 19:43:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEEm8RWbqF6ENOKUOAEQBjmFOnDVKm9mP+uQdgsx9OA4cNVuf3FIV2g3rNY9JWnjJJExAd X-Received: by 2002:a17:906:b248:: with SMTP id ce8mr1185743ejb.85.1597891381731; Wed, 19 Aug 2020 19:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597891381; cv=none; d=google.com; s=arc-20160816; b=I0QmJM9DswC2+iMnHh9laSajPSx+/JuGc5xNo9lD8P5CwkFVX+h5Gg6i6ftE+INYou lJEkt2PgoemyQ9iDDTcP6MP0YvfBb2fM5pqgzyfeMWtwhc0j+x2zdQeExuOCJi6DqiHx ZAgGn2VwGFRz4H/PxCeiG8mbD697pqIGTJnqzYES6HOhFOu7RQWhhIheUeddISFp/PEw /OOAFgPkSER8AxkxnpbTdZ4s+45FgHQHE9r2tOCcsW4PiVFkvERQL7B3XEwt2xvm8uDy yfdr4IunhTuHH2e4UmDcVjYRC7AvqG2DNOe1R3zbl9N8N3SaJOLWEf9Q9G3Pmk+JY07s 6DUw== 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; bh=nGHNlVhKHgb2Pi1A2+sPglsBGbxGVVh82cmu5gjGbp4=; b=YVqOtelj2XpmD0uRdApHIs7rzPspisflQl5rNTA/74eoVD8aocU9HZ8u6GoyvLqjMv cKsNWwYtkHdn0A/oybjzZmcHgN2T/DVVnfzCg5oAp8X+jepFo8i/Vh6+rWy8qvtRU/+l qq+foxsI4ibHI7vkg2WFAukKx5r83E6BJ2Y9L3E1/e2gyBrVYaw2IyuBX45v+XLuCeIT AQwZuTcQAh2bdu2eWgr4HSYO283YMXtukxMUvBWgTnDpl63y6iP0sA+zYuMA+s1TabFm K6k3Ugn09PCelj7LHy2aUXGTNn0t53fPjKEXhvaTiuMCFF14oXxaEhJ/WGgOM6Pd6Xco +jtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si330995ejz.395.2020.08.19.19.42.37; Wed, 19 Aug 2020 19:43:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726697AbgHTClC (ORCPT + 99 others); Wed, 19 Aug 2020 22:41:02 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:46060 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726435AbgHTClC (ORCPT ); Wed, 19 Aug 2020 22:41:02 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D0FA6B74D5D34CE20B31; Thu, 20 Aug 2020 10:40:58 +0800 (CST) Received: from huawei.com (10.175.112.208) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:40:52 +0800 From: Wang Wensheng To: , , , CC: , , Subject: [PATCH] watchdog: Add interface to config timeout and pretimeout in sysfs Date: Thu, 20 Aug 2020 02:38:58 +0000 Message-ID: <20200820023858.10873-1-wangwensheng4@huawei.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.208] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Those interfaces exist already in sysfs of watchdog driver core, but they are readonly. This patch add write hook so we can config timeout and pretimeout by writing those files. Signed-off-by: Wang Wensheng --- drivers/watchdog/watchdog_dev.c | 48 +++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 10b2090f3e5e..bb8ddc71d4ea 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -485,7 +485,29 @@ static ssize_t timeout_show(struct device *dev, struct device_attribute *attr, return sprintf(buf, "%u\n", wdd->timeout); } -static DEVICE_ATTR_RO(timeout); + +static ssize_t timeout_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + unsigned int val; + struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchdog_core_data *wd_data = wdd->wd_data; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + mutex_lock(&wd_data->lock); + ret = watchdog_set_timeout(wdd, val); + mutex_unlock(&wd_data->lock); + + if (!ret) + ret = count; + + return ret; +} +static DEVICE_ATTR_RW(timeout); static ssize_t pretimeout_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -494,7 +516,29 @@ static ssize_t pretimeout_show(struct device *dev, return sprintf(buf, "%u\n", wdd->pretimeout); } -static DEVICE_ATTR_RO(pretimeout); + +static ssize_t pretimeout_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int ret; + unsigned int val; + struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchdog_core_data *wd_data = wdd->wd_data; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + mutex_lock(&wd_data->lock); + ret = watchdog_set_pretimeout(wdd, val); + mutex_unlock(&wd_data->lock); + + if (!ret) + ret = count; + + return ret; +} +static DEVICE_ATTR_RW(pretimeout); static ssize_t identity_show(struct device *dev, struct device_attribute *attr, char *buf) -- 2.25.0