aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm87.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-14 23:58:08 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:04 -0400
commitc6370dbe45278db0ebebc377c0a6143b7c488379 (patch)
tree2d893c4423feed269aef31107d8771f2f976f3b7 /drivers/hwmon/lm87.c
parent525ad3731949fd9049254eabde57012d7cc06dbc (diff)
hwmon: (lm87) Fix checkpatch issues
Fixed: ERROR: do not use assignment in if condition ERROR: space required after that close brace '}' ERROR: space required after that ',' (ctx:VxV) ERROR: spaces required around that '<' (ctx:VxV) ERROR: trailing statements should be on next line WARNING: line over 80 characters WARNING: simple_strtol is obsolete, use kstrtol instead WARNING: simple_strtoul is obsolete, use kstrtoul instead Modify multi-line comments to follow Documentation/CodingStyle. Not fixed everywhere (code complexity): ERROR: do not use assignment in if condition As a side effect of the changes made, attribute set functions now return an error if an attempt is made to write non-numeric values. Previously, such writes were interpreted as writing 0. Cc: Jean Delvare <khali@linux-fr.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/lm87.c')
-rw-r--r--drivers/hwmon/lm87.c257
1 files changed, 174 insertions, 83 deletions
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 126d0cc42090..0216592a794b 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -119,20 +119,21 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
119 * The LM87 uses signed 8-bit values for temperatures. 119 * The LM87 uses signed 8-bit values for temperatures.
120 */ 120 */
121 121
122#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192) 122#define IN_FROM_REG(reg, scale) (((reg) * (scale) + 96) / 192)
123#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \ 123#define IN_TO_REG(val, scale) ((val) <= 0 ? 0 : \
124 (val) * 192 >= (scale) * 255 ? 255 : \ 124 (val) * 192 >= (scale) * 255 ? 255 : \
125 ((val) * 192 + (scale)/2) / (scale)) 125 ((val) * 192 + (scale) / 2) / (scale))
126 126
127#define TEMP_FROM_REG(reg) ((reg) * 1000) 127#define TEMP_FROM_REG(reg) ((reg) * 1000)
128#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \ 128#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
129 (val) >= 126500 ? 127 : \ 129 (val) >= 126500 ? 127 : \
130 (((val) < 0 ? (val)-500 : (val)+500) / 1000)) 130 (((val) < 0 ? (val) - 500 : \
131 (val) + 500) / 1000))
131 132
132#define FAN_FROM_REG(reg,div) ((reg) == 255 || (reg) == 0 ? 0 : \ 133#define FAN_FROM_REG(reg, div) ((reg) == 255 || (reg) == 0 ? 0 : \
133 (1350000 + (reg)*(div) / 2) / ((reg)*(div))) 134 (1350000 + (reg)*(div) / 2) / ((reg) * (div)))
134#define FAN_TO_REG(val,div) ((val)*(div) * 255 <= 1350000 ? 255 : \ 135#define FAN_TO_REG(val, div) ((val) * (div) * 255 <= 1350000 ? 255 : \
135 (1350000 + (val)*(div) / 2) / ((val)*(div))) 136 (1350000 + (val)*(div) / 2) / ((val) * (div)))
136 137
137#define FAN_DIV_FROM_REG(reg) (1 << (reg)) 138#define FAN_DIV_FROM_REG(reg) (1 << (reg))
138 139
@@ -232,19 +233,23 @@ static inline int lm87_write_value(struct i2c_client *client, u8 reg, u8 value)
232} 233}
233 234
234#define show_in(offset) \ 235#define show_in(offset) \
235static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 236static ssize_t show_in##offset##_input(struct device *dev, \
237 struct device_attribute *attr, \
238 char *buf) \
236{ \ 239{ \
237 struct lm87_data *data = lm87_update_device(dev); \ 240 struct lm87_data *data = lm87_update_device(dev); \
238 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ 241 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
239 data->in_scale[offset])); \ 242 data->in_scale[offset])); \
240} \ 243} \
241static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 244static ssize_t show_in##offset##_min(struct device *dev, \
245 struct device_attribute *attr, char *buf) \
242{ \ 246{ \
243 struct lm87_data *data = lm87_update_device(dev); \ 247 struct lm87_data *data = lm87_update_device(dev); \
244 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ 248 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
245 data->in_scale[offset])); \ 249 data->in_scale[offset])); \
246} \ 250} \
247static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ 251static ssize_t show_in##offset##_max(struct device *dev, \
252 struct device_attribute *attr, char *buf) \
248{ \ 253{ \
249 struct lm87_data *data = lm87_update_device(dev); \ 254 struct lm87_data *data = lm87_update_device(dev); \
250 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ 255 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
@@ -261,44 +266,58 @@ show_in(5);
261show_in(6); 266show_in(6);
262show_in(7); 267show_in(7);
263 268
264static void set_in_min(struct device *dev, const char *buf, int nr) 269static ssize_t set_in_min(struct device *dev, const char *buf, int nr,
270 size_t count)
265{ 271{
266 struct i2c_client *client = to_i2c_client(dev); 272 struct i2c_client *client = to_i2c_client(dev);
267 struct lm87_data *data = i2c_get_clientdata(client); 273 struct lm87_data *data = i2c_get_clientdata(client);
268 long val = simple_strtol(buf, NULL, 10); 274 long val;
275 int err;
276
277 err = kstrtol(buf, 10, &val);
278 if (err)
279 return err;
269 280
270 mutex_lock(&data->update_lock); 281 mutex_lock(&data->update_lock);
271 data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]); 282 data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]);
272 lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) : 283 lm87_write_value(client, nr < 6 ? LM87_REG_IN_MIN(nr) :
273 LM87_REG_AIN_MIN(nr-6), data->in_min[nr]); 284 LM87_REG_AIN_MIN(nr - 6), data->in_min[nr]);
274 mutex_unlock(&data->update_lock); 285 mutex_unlock(&data->update_lock);
286 return count;
275} 287}
276 288
277static void set_in_max(struct device *dev, const char *buf, int nr) 289static ssize_t set_in_max(struct device *dev, const char *buf, int nr,
290 size_t count)
278{ 291{
279 struct i2c_client *client = to_i2c_client(dev); 292 struct i2c_client *client = to_i2c_client(dev);
280 struct lm87_data *data = i2c_get_clientdata(client); 293 struct lm87_data *data = i2c_get_clientdata(client);
281 long val = simple_strtol(buf, NULL, 10); 294 long val;
295 int err;
296
297 err = kstrtol(buf, 10, &val);
298 if (err)
299 return err;
282 300
283 mutex_lock(&data->update_lock); 301 mutex_lock(&data->update_lock);
284 data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]); 302 data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]);
285 lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) : 303 lm87_write_value(client, nr < 6 ? LM87_REG_IN_MAX(nr) :
286 LM87_REG_AIN_MAX(nr-6), data->in_max[nr]); 304 LM87_REG_AIN_MAX(nr - 6), data->in_max[nr]);
287 mutex_unlock(&data->update_lock); 305 mutex_unlock(&data->update_lock);
306 return count;
288} 307}
289 308
290#define set_in(offset) \ 309#define set_in(offset) \
291static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, \ 310static ssize_t set_in##offset##_min(struct device *dev, \
292 const char *buf, size_t count) \ 311 struct device_attribute *attr, \
312 const char *buf, size_t count) \
293{ \ 313{ \
294 set_in_min(dev, buf, offset); \ 314 return set_in_min(dev, buf, offset, count); \
295 return count; \
296} \ 315} \
297static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, \ 316static ssize_t set_in##offset##_max(struct device *dev, \
298 const char *buf, size_t count) \ 317 struct device_attribute *attr, \
318 const char *buf, size_t count) \
299{ \ 319{ \
300 set_in_max(dev, buf, offset); \ 320 return set_in_max(dev, buf, offset, count); \
301 return count; \
302} \ 321} \
303static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 322static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
304 show_in##offset##_min, set_in##offset##_min); \ 323 show_in##offset##_min, set_in##offset##_min); \
@@ -314,63 +333,85 @@ set_in(6);
314set_in(7); 333set_in(7);
315 334
316#define show_temp(offset) \ 335#define show_temp(offset) \
317static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 336static ssize_t show_temp##offset##_input(struct device *dev, \
337 struct device_attribute *attr, \
338 char *buf) \
318{ \ 339{ \
319 struct lm87_data *data = lm87_update_device(dev); \ 340 struct lm87_data *data = lm87_update_device(dev); \
320 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ 341 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset - 1])); \
321} \ 342} \
322static ssize_t show_temp##offset##_low(struct device *dev, struct device_attribute *attr, char *buf) \ 343static ssize_t show_temp##offset##_low(struct device *dev, \
344 struct device_attribute *attr, \
345 char *buf) \
323{ \ 346{ \
324 struct lm87_data *data = lm87_update_device(dev); \ 347 struct lm87_data *data = lm87_update_device(dev); \
325 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[offset-1])); \ 348 return sprintf(buf, "%d\n", \
349 TEMP_FROM_REG(data->temp_low[offset - 1])); \
326} \ 350} \
327static ssize_t show_temp##offset##_high(struct device *dev, struct device_attribute *attr, char *buf) \ 351static ssize_t show_temp##offset##_high(struct device *dev, \
352 struct device_attribute *attr, \
353 char *buf) \
328{ \ 354{ \
329 struct lm87_data *data = lm87_update_device(dev); \ 355 struct lm87_data *data = lm87_update_device(dev); \
330 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[offset-1])); \ 356 return sprintf(buf, "%d\n", \
331}\ 357 TEMP_FROM_REG(data->temp_high[offset - 1])); \
358} \
332static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 359static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
333 show_temp##offset##_input, NULL); 360 show_temp##offset##_input, NULL);
334show_temp(1); 361show_temp(1);
335show_temp(2); 362show_temp(2);
336show_temp(3); 363show_temp(3);
337 364
338static void set_temp_low(struct device *dev, const char *buf, int nr) 365static ssize_t set_temp_low(struct device *dev, const char *buf, int nr,
366 size_t count)
339{ 367{
340 struct i2c_client *client = to_i2c_client(dev); 368 struct i2c_client *client = to_i2c_client(dev);
341 struct lm87_data *data = i2c_get_clientdata(client); 369 struct lm87_data *data = i2c_get_clientdata(client);
342 long val = simple_strtol(buf, NULL, 10); 370 long val;
371 int err;
372
373 err = kstrtol(buf, 10, &val);
374 if (err)
375 return err;
343 376
344 mutex_lock(&data->update_lock); 377 mutex_lock(&data->update_lock);
345 data->temp_low[nr] = TEMP_TO_REG(val); 378 data->temp_low[nr] = TEMP_TO_REG(val);
346 lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]); 379 lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]);
347 mutex_unlock(&data->update_lock); 380 mutex_unlock(&data->update_lock);
381 return count;
348} 382}
349 383
350static void set_temp_high(struct device *dev, const char *buf, int nr) 384static ssize_t set_temp_high(struct device *dev, const char *buf, int nr,
385 size_t count)
351{ 386{
352 struct i2c_client *client = to_i2c_client(dev); 387 struct i2c_client *client = to_i2c_client(dev);
353 struct lm87_data *data = i2c_get_clientdata(client); 388 struct lm87_data *data = i2c_get_clientdata(client);
354 long val = simple_strtol(buf, NULL, 10); 389 long val;
390 int err;
391
392 err = kstrtol(buf, 10, &val);
393 if (err)
394 return err;
355 395
356 mutex_lock(&data->update_lock); 396 mutex_lock(&data->update_lock);
357 data->temp_high[nr] = TEMP_TO_REG(val); 397 data->temp_high[nr] = TEMP_TO_REG(val);
358 lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]); 398 lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]);
359 mutex_unlock(&data->update_lock); 399 mutex_unlock(&data->update_lock);
400 return count;
360} 401}
361 402
362#define set_temp(offset) \ 403#define set_temp(offset) \
363static ssize_t set_temp##offset##_low(struct device *dev, struct device_attribute *attr, \ 404static ssize_t set_temp##offset##_low(struct device *dev, \
364 const char *buf, size_t count) \ 405 struct device_attribute *attr, \
406 const char *buf, size_t count) \
365{ \ 407{ \
366 set_temp_low(dev, buf, offset-1); \ 408 return set_temp_low(dev, buf, offset - 1, count); \
367 return count; \
368} \ 409} \
369static ssize_t set_temp##offset##_high(struct device *dev, struct device_attribute *attr, \ 410static ssize_t set_temp##offset##_high(struct device *dev, \
370 const char *buf, size_t count) \ 411 struct device_attribute *attr, \
412 const char *buf, size_t count) \
371{ \ 413{ \
372 set_temp_high(dev, buf, offset-1); \ 414 return set_temp_high(dev, buf, offset - 1, count); \
373 return count; \
374} \ 415} \
375static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ 416static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
376 show_temp##offset##_high, set_temp##offset##_high); \ 417 show_temp##offset##_high, set_temp##offset##_high); \
@@ -380,13 +421,15 @@ set_temp(1);
380set_temp(2); 421set_temp(2);
381set_temp(3); 422set_temp(3);
382 423
383static ssize_t show_temp_crit_int(struct device *dev, struct device_attribute *attr, char *buf) 424static ssize_t show_temp_crit_int(struct device *dev,
425 struct device_attribute *attr, char *buf)
384{ 426{
385 struct lm87_data *data = lm87_update_device(dev); 427 struct lm87_data *data = lm87_update_device(dev);
386 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_int)); 428 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_int));
387} 429}
388 430
389static ssize_t show_temp_crit_ext(struct device *dev, struct device_attribute *attr, char *buf) 431static ssize_t show_temp_crit_ext(struct device *dev,
432 struct device_attribute *attr, char *buf)
390{ 433{
391 struct lm87_data *data = lm87_update_device(dev); 434 struct lm87_data *data = lm87_update_device(dev);
392 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_ext)); 435 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_ext));
@@ -397,63 +440,92 @@ static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit_ext, NULL);
397static DEVICE_ATTR(temp3_crit, S_IRUGO, show_temp_crit_ext, NULL); 440static DEVICE_ATTR(temp3_crit, S_IRUGO, show_temp_crit_ext, NULL);
398 441
399#define show_fan(offset) \ 442#define show_fan(offset) \
400static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 443static ssize_t show_fan##offset##_input(struct device *dev, \
444 struct device_attribute *attr, \
445 char *buf) \
401{ \ 446{ \
402 struct lm87_data *data = lm87_update_device(dev); \ 447 struct lm87_data *data = lm87_update_device(dev); \
403 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[offset-1], \ 448 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[offset - 1], \
404 FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \ 449 FAN_DIV_FROM_REG(data->fan_div[offset - 1]))); \
405} \ 450} \
406static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 451static ssize_t show_fan##offset##_min(struct device *dev, \
452 struct device_attribute *attr, \
453 char *buf) \
407{ \ 454{ \
408 struct lm87_data *data = lm87_update_device(dev); \ 455 struct lm87_data *data = lm87_update_device(dev); \
409 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[offset-1], \ 456 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[offset - 1], \
410 FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \ 457 FAN_DIV_FROM_REG(data->fan_div[offset - 1]))); \
411} \ 458} \
412static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \ 459static ssize_t show_fan##offset##_div(struct device *dev, \
460 struct device_attribute *attr, \
461 char *buf) \
413{ \ 462{ \
414 struct lm87_data *data = lm87_update_device(dev); \ 463 struct lm87_data *data = lm87_update_device(dev); \
415 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[offset-1])); \ 464 return sprintf(buf, "%d\n", \
465 FAN_DIV_FROM_REG(data->fan_div[offset - 1])); \
416} \ 466} \
417static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 467static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
418 show_fan##offset##_input, NULL); 468 show_fan##offset##_input, NULL);
419show_fan(1); 469show_fan(1);
420show_fan(2); 470show_fan(2);
421 471
422static void set_fan_min(struct device *dev, const char *buf, int nr) 472static ssize_t set_fan_min(struct device *dev, const char *buf, int nr,
473 size_t count)
423{ 474{
424 struct i2c_client *client = to_i2c_client(dev); 475 struct i2c_client *client = to_i2c_client(dev);
425 struct lm87_data *data = i2c_get_clientdata(client); 476 struct lm87_data *data = i2c_get_clientdata(client);
426 long val = simple_strtol(buf, NULL, 10); 477 long val;
478 int err;
479
480 err = kstrtol(buf, 10, &val);
481 if (err)
482 return err;
427 483
428 mutex_lock(&data->update_lock); 484 mutex_lock(&data->update_lock);
429 data->fan_min[nr] = FAN_TO_REG(val, 485 data->fan_min[nr] = FAN_TO_REG(val,
430 FAN_DIV_FROM_REG(data->fan_div[nr])); 486 FAN_DIV_FROM_REG(data->fan_div[nr]));
431 lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]); 487 lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]);
432 mutex_unlock(&data->update_lock); 488 mutex_unlock(&data->update_lock);
489 return count;
433} 490}
434 491
435/* Note: we save and restore the fan minimum here, because its value is 492/*
436 determined in part by the fan clock divider. This follows the principle 493 * Note: we save and restore the fan minimum here, because its value is
437 of least surprise; the user doesn't expect the fan minimum to change just 494 * determined in part by the fan clock divider. This follows the principle
438 because the divider changed. */ 495 * of least surprise; the user doesn't expect the fan minimum to change just
496 * because the divider changed.
497 */
439static ssize_t set_fan_div(struct device *dev, const char *buf, 498static ssize_t set_fan_div(struct device *dev, const char *buf,
440 size_t count, int nr) 499 size_t count, int nr)
441{ 500{
442 struct i2c_client *client = to_i2c_client(dev); 501 struct i2c_client *client = to_i2c_client(dev);
443 struct lm87_data *data = i2c_get_clientdata(client); 502 struct lm87_data *data = i2c_get_clientdata(client);
444 long val = simple_strtol(buf, NULL, 10); 503 long val;
504 int err;
445 unsigned long min; 505 unsigned long min;
446 u8 reg; 506 u8 reg;
447 507
508 err = kstrtol(buf, 10, &val);
509 if (err)
510 return err;
511
448 mutex_lock(&data->update_lock); 512 mutex_lock(&data->update_lock);
449 min = FAN_FROM_REG(data->fan_min[nr], 513 min = FAN_FROM_REG(data->fan_min[nr],
450 FAN_DIV_FROM_REG(data->fan_div[nr])); 514 FAN_DIV_FROM_REG(data->fan_div[nr]));
451 515
452 switch (val) { 516 switch (val) {
453 case 1: data->fan_div[nr] = 0; break; 517 case 1:
454 case 2: data->fan_div[nr] = 1; break; 518 data->fan_div[nr] = 0;
455 case 4: data->fan_div[nr] = 2; break; 519 break;
456 case 8: data->fan_div[nr] = 3; break; 520 case 2:
521 data->fan_div[nr] = 1;
522 break;
523 case 4:
524 data->fan_div[nr] = 2;
525 break;
526 case 8:
527 data->fan_div[nr] = 3;
528 break;
457 default: 529 default:
458 mutex_unlock(&data->update_lock); 530 mutex_unlock(&data->update_lock);
459 return -EINVAL; 531 return -EINVAL;
@@ -479,16 +551,17 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
479} 551}
480 552
481#define set_fan(offset) \ 553#define set_fan(offset) \
482static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 554static ssize_t set_fan##offset##_min(struct device *dev, \
483 size_t count) \ 555 struct device_attribute *attr, \
556 const char *buf, size_t count) \
484{ \ 557{ \
485 set_fan_min(dev, buf, offset-1); \ 558 return set_fan_min(dev, buf, offset - 1, count); \
486 return count; \
487} \ 559} \
488static ssize_t set_fan##offset##_div(struct device *dev, struct device_attribute *attr, const char *buf, \ 560static ssize_t set_fan##offset##_div(struct device *dev, \
489 size_t count) \ 561 struct device_attribute *attr, \
562 const char *buf, size_t count) \
490{ \ 563{ \
491 return set_fan_div(dev, buf, count, offset-1); \ 564 return set_fan_div(dev, buf, count, offset - 1); \
492} \ 565} \
493static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 566static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
494 show_fan##offset##_min, set_fan##offset##_min); \ 567 show_fan##offset##_min, set_fan##offset##_min); \
@@ -497,43 +570,60 @@ static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
497set_fan(1); 570set_fan(1);
498set_fan(2); 571set_fan(2);
499 572
500static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 573static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
574 char *buf)
501{ 575{
502 struct lm87_data *data = lm87_update_device(dev); 576 struct lm87_data *data = lm87_update_device(dev);
503 return sprintf(buf, "%d\n", data->alarms); 577 return sprintf(buf, "%d\n", data->alarms);
504} 578}
505static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 579static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
506 580
507static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 581static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
582 char *buf)
508{ 583{
509 struct lm87_data *data = lm87_update_device(dev); 584 struct lm87_data *data = lm87_update_device(dev);
510 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 585 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
511} 586}
512static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 587static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
513 588
514static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 589static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
590 char *buf)
515{ 591{
516 struct lm87_data *data = dev_get_drvdata(dev); 592 struct lm87_data *data = dev_get_drvdata(dev);
517 return sprintf(buf, "%d\n", data->vrm); 593 return sprintf(buf, "%d\n", data->vrm);
518} 594}
519static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 595static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
596 const char *buf, size_t count)
520{ 597{
521 struct lm87_data *data = dev_get_drvdata(dev); 598 struct lm87_data *data = dev_get_drvdata(dev);
522 data->vrm = simple_strtoul(buf, NULL, 10); 599 unsigned long val;
600 int err;
601
602 err = kstrtoul(buf, 10, &val);
603 if (err)
604 return err;
605 data->vrm = val;
523 return count; 606 return count;
524} 607}
525static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 608static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
526 609
527static ssize_t show_aout(struct device *dev, struct device_attribute *attr, char *buf) 610static ssize_t show_aout(struct device *dev, struct device_attribute *attr,
611 char *buf)
528{ 612{
529 struct lm87_data *data = lm87_update_device(dev); 613 struct lm87_data *data = lm87_update_device(dev);
530 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout)); 614 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
531} 615}
532static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 616static ssize_t set_aout(struct device *dev, struct device_attribute *attr,
617 const char *buf, size_t count)
533{ 618{
534 struct i2c_client *client = to_i2c_client(dev); 619 struct i2c_client *client = to_i2c_client(dev);
535 struct lm87_data *data = i2c_get_clientdata(client); 620 struct lm87_data *data = i2c_get_clientdata(client);
536 long val = simple_strtol(buf, NULL, 10); 621 long val;
622 int err;
623
624 err = kstrtol(buf, 10, &val);
625 if (err)
626 return err;
537 627
538 mutex_lock(&data->update_lock); 628 mutex_lock(&data->update_lock);
539 data->aout = AOUT_TO_REG(val); 629 data->aout = AOUT_TO_REG(val);
@@ -721,7 +811,8 @@ static int lm87_probe(struct i2c_client *new_client,
721 data->in_scale[7] = 1875; 811 data->in_scale[7] = 1875;
722 812
723 /* Register sysfs hooks */ 813 /* Register sysfs hooks */
724 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group))) 814 err = sysfs_create_group(&new_client->dev.kobj, &lm87_group);
815 if (err)
725 goto exit_free; 816 goto exit_free;
726 817
727 if (data->channel & CHAN_NO_FAN(0)) { 818 if (data->channel & CHAN_NO_FAN(0)) {