* [PATCH] hwmon: adt7470: Add write support to alarm_mask
@ 2016-08-21 22:01 Joshua Scott
0 siblings, 0 replies; 3+ messages in thread
From: Joshua Scott @ 2016-08-21 22:01 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, linux-hwmon; +Cc: Joshua Scott, Chris Packham
Add write support for the alarm_mask. A base of 0 is provided so that
either hex or decimal can be used. The hex format when reading alarm_mask
is unchanged.
Signed-off-by: Joshua Scott <joshua.scott@alliedtelesis.co.nz>
---
drivers/hwmon/adt7470.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 94550d7..7d185a9 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -545,6 +545,27 @@ static ssize_t show_alarm_mask(struct device *dev,
return sprintf(buf, "%x\n", data->alarms_mask);
}
+static ssize_t set_alarm_mask(struct device *dev,
+ struct device_attribute *devattr,
+ const char *buf,
+ size_t count)
+{
+ struct adt7470_data *data = dev_get_drvdata(dev);
+ long mask;
+
+ if (kstrtol(buf, 0, &mask))
+ return -EINVAL;
+
+ mask &= 0xffff;
+
+ mutex_lock(&data->lock);
+ data->alarms_mask = mask;
+ adt7470_write_word_data(data->client, ADT7470_REG_ALARM1_MASK, mask);
+ mutex_unlock(&data->lock);
+
+ return count;
+}
+
static ssize_t show_fan_max(struct device *dev,
struct device_attribute *devattr,
char *buf)
@@ -989,7 +1010,8 @@ static ssize_t show_alarm(struct device *dev,
return sprintf(buf, "0\n");
}
-static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
+static DEVICE_ATTR(alarm_mask, S_IWUSR | S_IRUGO, show_alarm_mask,
+ set_alarm_mask);
static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors,
set_num_temp_sensors);
static DEVICE_ATTR(auto_update_interval, S_IWUSR | S_IRUGO,
--
2.9.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: adt7470: Add write support to alarm_mask
2016-09-06 22:25 Joshua Scott
@ 2016-09-09 4:14 ` Guenter Roeck
0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2016-09-09 4:14 UTC (permalink / raw)
To: Joshua Scott, Jean Delvare, linux-hwmon; +Cc: Chris Packham
On 09/06/2016 03:25 PM, Joshua Scott wrote:
> Add write support for the alarm_mask. A base of 0 is provided so that
> either hex or decimal can be used. The hex format when reading alarm_mask
> is unchanged.
>
> Signed-off-by: Joshua Scott <joshua.scott@alliedtelesis.co.nz>
> ---
> drivers/hwmon/adt7470.c | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index 94550d7..7d185a9 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -545,6 +545,27 @@ static ssize_t show_alarm_mask(struct device *dev,
> return sprintf(buf, "%x\n", data->alarms_mask);
> }
>
> +static ssize_t set_alarm_mask(struct device *dev,
> + struct device_attribute *devattr,
> + const char *buf,
> + size_t count)
> +{
> + struct adt7470_data *data = dev_get_drvdata(dev);
> + long mask;
> +
> + if (kstrtol(buf, 0, &mask))
This accepts negative values. Please consider unsigned long and kstrtoul().
> + return -EINVAL;
> +
> + mask &= 0xffff;
> +
This accepts and auto-fixes a bad provided mask. Please make it something like
if (mask & ~0xffff)
return -EINVAL;
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] hwmon: adt7470: Add write support to alarm_mask
@ 2016-09-06 22:25 Joshua Scott
2016-09-09 4:14 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: Joshua Scott @ 2016-09-06 22:25 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, linux-hwmon; +Cc: Joshua Scott, Chris Packham
Add write support for the alarm_mask. A base of 0 is provided so that
either hex or decimal can be used. The hex format when reading alarm_mask
is unchanged.
Signed-off-by: Joshua Scott <joshua.scott@alliedtelesis.co.nz>
---
drivers/hwmon/adt7470.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 94550d7..7d185a9 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -545,6 +545,27 @@ static ssize_t show_alarm_mask(struct device *dev,
return sprintf(buf, "%x\n", data->alarms_mask);
}
+static ssize_t set_alarm_mask(struct device *dev,
+ struct device_attribute *devattr,
+ const char *buf,
+ size_t count)
+{
+ struct adt7470_data *data = dev_get_drvdata(dev);
+ long mask;
+
+ if (kstrtol(buf, 0, &mask))
+ return -EINVAL;
+
+ mask &= 0xffff;
+
+ mutex_lock(&data->lock);
+ data->alarms_mask = mask;
+ adt7470_write_word_data(data->client, ADT7470_REG_ALARM1_MASK, mask);
+ mutex_unlock(&data->lock);
+
+ return count;
+}
+
static ssize_t show_fan_max(struct device *dev,
struct device_attribute *devattr,
char *buf)
@@ -989,7 +1010,8 @@ static ssize_t show_alarm(struct device *dev,
return sprintf(buf, "0\n");
}
-static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
+static DEVICE_ATTR(alarm_mask, S_IWUSR | S_IRUGO, show_alarm_mask,
+ set_alarm_mask);
static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors,
set_num_temp_sensors);
static DEVICE_ATTR(auto_update_interval, S_IWUSR | S_IRUGO,
--
2.9.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-09 4:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-21 22:01 [PATCH] hwmon: adt7470: Add write support to alarm_mask Joshua Scott
2016-09-06 22:25 Joshua Scott
2016-09-09 4:14 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.