lkml.org 
[lkml]   [2014]   [Sep]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH 3.2 035/131] hwmon: (lm85) Fix various errors on attribute writes
3.2.63-rc1 review patch.  If anyone has any objections, please let me know.

------------------

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

commit 3248c3b771ddd9d31695da17ba350eb6e1b80a53 upstream.

Temperature limit register writes did not account for negative numbers.
As a result, writing -127000 resulted in -126000 written into the
temperature limit register. This problem affected temp[1-3]_min,
temp[1-3]_max, temp[1-3]_auto_temp_crit, and temp[1-3]_auto_temp_min.

When writing pwm[1-3]_freq, a long variable was auto-converted into an int
without range check. Wiring values larger than MAXINT resulted in unexpected
register values.

When writing temp[1-3]_auto_temp_max, an unsigned long variable was
auto-converted into an int without range check. Writing values larger than
MAXINT resulted in unexpected register values.

vrm is an u8, so the written value needs to be limited to [0, 255].

Cc: Axel Lin <axel.lin@ingics.com>
Reviewed-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
[bwh: Backported to 3.2:
- Driver is not using clamp_val(); keep using SENSORS_LIMIT() for consistency
- Driver is not using kstrtoul(); make the minimum change to store_vrm_reg()
so we can validate the value before assigning]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -157,7 +157,7 @@ static inline u16 FAN_TO_REG(unsigned lo

/* Temperature is reported in .001 degC increments */
#define TEMP_TO_REG(val) \
- SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127)
+ DIV_ROUND_CLOSEST(SENSORS_LIMIT((val), -127000, 127000), 1000)
#define TEMPEXT_FROM_REG(val, ext) \
SCALE(((val) << 4) + (ext), 16, 1000)
#define TEMP_FROM_REG(val) ((val) * 1000)
@@ -190,7 +190,7 @@ static const int lm85_range_map[] = {
13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
};

-static int RANGE_TO_REG(int range)
+static int RANGE_TO_REG(long range)
{
int i;

@@ -212,7 +212,7 @@ static const int adm1027_freq_map[8] = {
11, 15, 22, 29, 35, 44, 59, 88
};

-static int FREQ_TO_REG(const int *map, int freq)
+static int FREQ_TO_REG(const int *map, unsigned long freq)
{
int i;

@@ -443,7 +443,13 @@ static ssize_t store_vrm_reg(struct devi
const char *buf, size_t count)
{
struct lm85_data *data = dev_get_drvdata(dev);
- data->vrm = simple_strtoul(buf, NULL, 10);
+ unsigned long val;
+
+ val = simple_strtoul(buf, NULL, 10);
+ if (val > 255)
+ return -EINVAL;
+
+ data->vrm = val;
return count;
}



\
 
 \ /
  Last update: 2014-09-11 15:21    [W:0.587 / U:0.628 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site