Report i2c errors to userspace in lm73 driver

Fix problem with DIV_ROUND_CLOSEST and unsigned divisors in emc6w201 driver
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.11 (GNU/Linux)
 
 iQIcBAABAgAGBQJQ11BwAAoJEMsfJm/On5mBQrEP/0mnrSDdrtIRL04x1g3zvcmW
 Bd6Eq2utwll2+3KisModNm1Jetshw1wXOW5CE/IhpsJoxDfd1PE0+jKF8pY/IBVS
 pBVOk9K2er+i4tRNEjMjpe/w+nxKGISfrkF9hKFpGE0kfiM4mz6yoj1EwIX7OHZf
 wBeJC7upvRS+MYzT0tffBTkRFR2yEV4bUH2tur/xDrFnWljNA2SGc62QAQXAIhYh
 fmV6T8Zxbms7L+Q0g3b9UMMIFiAf/5IvF6DPnXuJqoPRYdyD7x0UMr6JiuagLWwH
 0IQoLRzTewvGhwCmpZTWKFMhwjXhwxdB31PtBWg+xScPDL8ty98Fb0IsYSUORjTh
 dy+GFTmQKAmMnnq6+Jl4WebNZwf8NrjiDAe+kV05FeGHacEgAYR/e+KRzfB0yCRv
 8hWAm2wXCOZVlaqJozTenmoUsLft+QXEZ1GZu+r9xNPIDXBy90j4toOkfh98FUoO
 1W+FbMMhYM1Hx+gpwneEIl0gtHityzcgnxgZVGXkoGAuevnQXvIbtbPtpPeJG9XD
 I6JOhBpvYdB6Ka198vAwQNpPAs7omlKCWJ7ZiAFlOjAu8W1fQjbZ+NtBtEtCEBHA
 KT1f/jgS8V6vRZg0Dors3u7Cc58eyHrnmpYlsJlSDyNQmYtvuBx3NAGQGKvwZhQ1
 R0Vi3N9eZwjrlw+bkKih
 =2sDG
 -----END PGP SIGNATURE-----

Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon fixes from Guenter Roeck:

 - Report i2c errors to userspace in lm73 driver

 - Fix problem with DIV_ROUND_CLOSEST and unsigned divisors in emc6w201
   driver

* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
  hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors
  hwmon: (lm73} Detect and report i2c bus errors
This commit is contained in:
Linus Torvalds 2012-12-27 10:46:47 -08:00
commit 101e5c7470
2 changed files with 12 additions and 6 deletions

View file

@ -187,7 +187,7 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
* Sysfs callback functions
*/
static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
char *buf)

View file

@ -49,6 +49,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
struct i2c_client *client = to_i2c_client(dev);
long temp;
short value;
s32 err;
int status = kstrtol(buf, 10, &temp);
if (status < 0)
@ -57,8 +58,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
/* Write value */
value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4),
(LM73_TEMP_MAX*4)) << 5;
i2c_smbus_write_word_swapped(client, attr->index, value);
return count;
err = i2c_smbus_write_word_swapped(client, attr->index, value);
return (err < 0) ? err : count;
}
static ssize_t show_temp(struct device *dev, struct device_attribute *da,
@ -66,11 +67,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da,
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct i2c_client *client = to_i2c_client(dev);
int temp;
s32 err = i2c_smbus_read_word_swapped(client, attr->index);
if (err < 0)
return err;
/* use integer division instead of equivalent right shift to
guarantee arithmetic shift and preserve the sign */
int temp = ((s16) (i2c_smbus_read_word_swapped(client,
attr->index))*250) / 32;
return sprintf(buf, "%d\n", temp);
temp = (((s16) err) * 250) / 32;
return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
}