Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (vt8231) use permission-specific DEVICE_ATTR variants

Use DEVICE_ATTR_RO for read only attributes and DEVICE_ATTR_RW for
read/write attributes. This simplifies the source code, improves
readbility, and reduces the chance of inconsistencies.

The conversion was done automatically using coccinelle. It was validated
by compiling both the old and the new source code and comparing its text,
data, and bss size.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
[groeck: Updated description]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Julia Lawall and committed by
Guenter Roeck
d5034db6 329beb71

+31 -28
+31 -28
drivers/hwmon/vt8231.c
··· 263 263 } 264 264 265 265 /* Special case for input 5 as this has 3.3V scaling built into the chip */ 266 - static ssize_t show_in5(struct device *dev, struct device_attribute *attr, 267 - char *buf) 266 + static ssize_t in5_input_show(struct device *dev, 267 + struct device_attribute *attr, char *buf) 268 268 { 269 269 struct vt8231_data *data = vt8231_update_device(dev); 270 270 ··· 272 272 (((data->in[5] - 3) * 10000 * 54) / (958 * 34))); 273 273 } 274 274 275 - static ssize_t show_in5_min(struct device *dev, struct device_attribute *attr, 275 + static ssize_t in5_min_show(struct device *dev, struct device_attribute *attr, 276 276 char *buf) 277 277 { 278 278 struct vt8231_data *data = vt8231_update_device(dev); ··· 281 281 (((data->in_min[5] - 3) * 10000 * 54) / (958 * 34))); 282 282 } 283 283 284 - static ssize_t show_in5_max(struct device *dev, struct device_attribute *attr, 284 + static ssize_t in5_max_show(struct device *dev, struct device_attribute *attr, 285 285 char *buf) 286 286 { 287 287 struct vt8231_data *data = vt8231_update_device(dev); ··· 290 290 (((data->in_max[5] - 3) * 10000 * 54) / (958 * 34))); 291 291 } 292 292 293 - static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, 294 - const char *buf, size_t count) 293 + static ssize_t in5_min_store(struct device *dev, 294 + struct device_attribute *attr, const char *buf, 295 + size_t count) 295 296 { 296 297 struct vt8231_data *data = dev_get_drvdata(dev); 297 298 unsigned long val; ··· 310 309 return count; 311 310 } 312 311 313 - static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, 314 - const char *buf, size_t count) 312 + static ssize_t in5_max_store(struct device *dev, 313 + struct device_attribute *attr, const char *buf, 314 + size_t count) 315 315 { 316 316 struct vt8231_data *data = dev_get_drvdata(dev); 317 317 unsigned long val; ··· 344 342 define_voltage_sysfs(3); 345 343 define_voltage_sysfs(4); 346 344 347 - static DEVICE_ATTR(in5_input, S_IRUGO, show_in5, NULL); 348 - static DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR, show_in5_min, set_in5_min); 349 - static DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR, show_in5_max, set_in5_max); 345 + static DEVICE_ATTR_RO(in5_input); 346 + static DEVICE_ATTR_RW(in5_min); 347 + static DEVICE_ATTR_RW(in5_max); 350 348 351 349 /* Temperatures */ 352 - static ssize_t show_temp0(struct device *dev, struct device_attribute *attr, 353 - char *buf) 350 + static ssize_t temp1_input_show(struct device *dev, 351 + struct device_attribute *attr, char *buf) 354 352 { 355 353 struct vt8231_data *data = vt8231_update_device(dev); 356 354 return sprintf(buf, "%d\n", data->temp[0] * 250); 357 355 } 358 356 359 - static ssize_t show_temp0_max(struct device *dev, struct device_attribute *attr, 357 + static ssize_t temp1_max_show(struct device *dev, struct device_attribute *attr, 360 358 char *buf) 361 359 { 362 360 struct vt8231_data *data = vt8231_update_device(dev); 363 361 return sprintf(buf, "%d\n", data->temp_max[0] * 1000); 364 362 } 365 363 366 - static ssize_t show_temp0_min(struct device *dev, struct device_attribute *attr, 367 - char *buf) 364 + static ssize_t temp1_max_hyst_show(struct device *dev, 365 + struct device_attribute *attr, char *buf) 368 366 { 369 367 struct vt8231_data *data = vt8231_update_device(dev); 370 368 return sprintf(buf, "%d\n", data->temp_min[0] * 1000); 371 369 } 372 370 373 - static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, 374 - const char *buf, size_t count) 371 + static ssize_t temp1_max_store(struct device *dev, 372 + struct device_attribute *attr, const char *buf, 373 + size_t count) 375 374 { 376 375 struct vt8231_data *data = dev_get_drvdata(dev); 377 376 long val; ··· 388 385 mutex_unlock(&data->update_lock); 389 386 return count; 390 387 } 391 - static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, 392 - const char *buf, size_t count) 388 + static ssize_t temp1_max_hyst_store(struct device *dev, 389 + struct device_attribute *attr, 390 + const char *buf, size_t count) 393 391 { 394 392 struct vt8231_data *data = dev_get_drvdata(dev); 395 393 long val; ··· 485 481 static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ 486 482 show_temp_min, set_temp_min, offset - 1) 487 483 488 - static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL); 489 - static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max); 490 - static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min, 491 - set_temp0_min); 484 + static DEVICE_ATTR_RO(temp1_input); 485 + static DEVICE_ATTR_RW(temp1_max); 486 + static DEVICE_ATTR_RW(temp1_max_hyst); 492 487 493 488 define_temperature_sysfs(2); 494 489 define_temperature_sysfs(3); ··· 606 603 define_fan_sysfs(2); 607 604 608 605 /* Alarms */ 609 - static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, 606 + static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, 610 607 char *buf) 611 608 { 612 609 struct vt8231_data *data = vt8231_update_device(dev); 613 610 return sprintf(buf, "%d\n", data->alarms); 614 611 } 615 - static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 612 + static DEVICE_ATTR_RO(alarms); 616 613 617 614 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, 618 615 char *buf) ··· 636 633 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); 637 634 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); 638 635 639 - static ssize_t show_name(struct device *dev, struct device_attribute 636 + static ssize_t name_show(struct device *dev, struct device_attribute 640 637 *devattr, char *buf) 641 638 { 642 639 struct vt8231_data *data = dev_get_drvdata(dev); 643 640 return sprintf(buf, "%s\n", data->name); 644 641 } 645 - static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 642 + static DEVICE_ATTR_RO(name); 646 643 647 644 static struct attribute *vt8231_attributes_temps[6][5] = { 648 645 {