watchdog: Add {min,max}_timeout sysfs nodes

Message ID 20210510131625.21506-1-juergh@canonical.com
State Superseded
Headers show
Series
  • watchdog: Add {min,max}_timeout sysfs nodes
Related show

Commit Message

Juerg Haefliger May 10, 2021, 1:16 p.m.
The valid range for the 'timeout' value is useful information so expose
the min and max timeout values via sysfs.

Signed-off-by: Juerg Haefliger <juergh@canonical.com>
---
 drivers/watchdog/watchdog_dev.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Juerg Haefliger May 10, 2021, 2:14 p.m. | #1
On Mon, 10 May 2021 06:45:15 -0700
Guenter Roeck <linux@roeck-us.net> wrote:

> On 5/10/21 6:16 AM, Juerg Haefliger wrote:
> > The valid range for the 'timeout' value is useful information so expose
> > the min and max timeout values via sysfs.
> > 
> > Signed-off-by: Juerg Haefliger <juergh@canonical.com>
> > ---
> >   drivers/watchdog/watchdog_dev.c | 20 ++++++++++++++++++++
> >   1 file changed, 20 insertions(+)
> > 
> > diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> > index 2946f3a63110..b84d53a79618 100644
> > --- a/drivers/watchdog/watchdog_dev.c
> > +++ b/drivers/watchdog/watchdog_dev.c
> > @@ -525,6 +525,24 @@ static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,
> >   }
> >   static DEVICE_ATTR_RO(timeout);
> >   
> > +static ssize_t min_timeout_show(struct device *dev,
> > +				struct device_attribute *attr, char *buf)
> > +{
> > +	struct watchdog_device *wdd = dev_get_drvdata(dev);
> > +
> > +	return sprintf(buf, "%u\n", wdd->min_timeout);
> > +}
> > +static DEVICE_ATTR_RO(min_timeout);
> > +
> > +static ssize_t max_timeout_show(struct device *dev,
> > +				struct device_attribute *attr, char *buf)
> > +{
> > +	struct watchdog_device *wdd = dev_get_drvdata(dev);
> > +
> > +	return sprintf(buf, "%u\n", wdd->max_timeout);  
> 
> Makes sense, but please use sysfs_emit().

OK. And maybe I should send a patch to convert the other occurrences of
sprintf as well?

...Juerg


> Guenter
> 
> > +}
> > +static DEVICE_ATTR_RO(max_timeout);
> > +
> >   static ssize_t pretimeout_show(struct device *dev,
> >   			       struct device_attribute *attr, char *buf)
> >   {
> > @@ -609,6 +627,8 @@ static struct attribute *wdt_attrs[] = {
> >   	&dev_attr_state.attr,
> >   	&dev_attr_identity.attr,
> >   	&dev_attr_timeout.attr,
> > +	&dev_attr_min_timeout.attr,
> > +	&dev_attr_max_timeout.attr,
> >   	&dev_attr_pretimeout.attr,
> >   	&dev_attr_timeleft.attr,
> >   	&dev_attr_bootstatus.attr,
> >   
>
Guenter Roeck May 10, 2021, 2:56 p.m. | #2
On 5/10/21 7:14 AM, Juerg Haefliger wrote:
> On Mon, 10 May 2021 06:45:15 -0700
> Guenter Roeck <linux@roeck-us.net> wrote:
> 
>> On 5/10/21 6:16 AM, Juerg Haefliger wrote:
>>> The valid range for the 'timeout' value is useful information so expose
>>> the min and max timeout values via sysfs.
>>>
>>> Signed-off-by: Juerg Haefliger <juergh@canonical.com>
>>> ---
>>>    drivers/watchdog/watchdog_dev.c | 20 ++++++++++++++++++++
>>>    1 file changed, 20 insertions(+)
>>>
>>> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
>>> index 2946f3a63110..b84d53a79618 100644
>>> --- a/drivers/watchdog/watchdog_dev.c
>>> +++ b/drivers/watchdog/watchdog_dev.c
>>> @@ -525,6 +525,24 @@ static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,
>>>    }
>>>    static DEVICE_ATTR_RO(timeout);
>>>    
>>> +static ssize_t min_timeout_show(struct device *dev,
>>> +				struct device_attribute *attr, char *buf)
>>> +{
>>> +	struct watchdog_device *wdd = dev_get_drvdata(dev);
>>> +
>>> +	return sprintf(buf, "%u\n", wdd->min_timeout);
>>> +}
>>> +static DEVICE_ATTR_RO(min_timeout);
>>> +
>>> +static ssize_t max_timeout_show(struct device *dev,
>>> +				struct device_attribute *attr, char *buf)
>>> +{
>>> +	struct watchdog_device *wdd = dev_get_drvdata(dev);
>>> +
>>> +	return sprintf(buf, "%u\n", wdd->max_timeout);
>>
>> Makes sense, but please use sysfs_emit().
> 
> OK. And maybe I should send a patch to convert the other occurrences of
> sprintf as well?
> 

Sure, if you want to.

Guenter
Guenter Roeck May 11, 2021, 1:35 p.m. | #3
On 5/10/21 11:29 PM, Juerg Haefliger wrote:
> The valid range for the 'timeout' value is useful information so expose

> the min and max timeout values via sysfs.

> 

> Signed-off-by: Juerg Haefliger <juergh@canonical.com>


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


> ---

> 

> v1->v2:

>   - replace sprintf() with sysfs_emit().

> 

>   drivers/watchdog/watchdog_dev.c | 20 ++++++++++++++++++++

>   1 file changed, 20 insertions(+)

> 

> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c

> index fe68a97973a5..7c1007ab1b71 100644

> --- a/drivers/watchdog/watchdog_dev.c

> +++ b/drivers/watchdog/watchdog_dev.c

> @@ -526,6 +526,24 @@ static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,

>   }

>   static DEVICE_ATTR_RO(timeout);

>   

> +static ssize_t min_timeout_show(struct device *dev,

> +				struct device_attribute *attr, char *buf)

> +{

> +	struct watchdog_device *wdd = dev_get_drvdata(dev);

> +

> +	return sysfs_emit(buf, "%u\n", wdd->min_timeout);

> +}

> +static DEVICE_ATTR_RO(min_timeout);

> +

> +static ssize_t max_timeout_show(struct device *dev,

> +				struct device_attribute *attr, char *buf)

> +{

> +	struct watchdog_device *wdd = dev_get_drvdata(dev);

> +

> +	return sysfs_emit(buf, "%u\n", wdd->max_timeout);

> +}

> +static DEVICE_ATTR_RO(max_timeout);

> +

>   static ssize_t pretimeout_show(struct device *dev,

>   			       struct device_attribute *attr, char *buf)

>   {

> @@ -610,6 +628,8 @@ static struct attribute *wdt_attrs[] = {

>   	&dev_attr_state.attr,

>   	&dev_attr_identity.attr,

>   	&dev_attr_timeout.attr,

> +	&dev_attr_min_timeout.attr,

> +	&dev_attr_max_timeout.attr,

>   	&dev_attr_pretimeout.attr,

>   	&dev_attr_timeleft.attr,

>   	&dev_attr_bootstatus.attr,

>

Patch

diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 2946f3a63110..b84d53a79618 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -525,6 +525,24 @@  static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(timeout);
 
+static ssize_t min_timeout_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct watchdog_device *wdd = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", wdd->min_timeout);
+}
+static DEVICE_ATTR_RO(min_timeout);
+
+static ssize_t max_timeout_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct watchdog_device *wdd = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", wdd->max_timeout);
+}
+static DEVICE_ATTR_RO(max_timeout);
+
 static ssize_t pretimeout_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
@@ -609,6 +627,8 @@  static struct attribute *wdt_attrs[] = {
 	&dev_attr_state.attr,
 	&dev_attr_identity.attr,
 	&dev_attr_timeout.attr,
+	&dev_attr_min_timeout.attr,
+	&dev_attr_max_timeout.attr,
 	&dev_attr_pretimeout.attr,
 	&dev_attr_timeleft.attr,
 	&dev_attr_bootstatus.attr,