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

driver core: Convert some drivers to CLASS_ATTR_STRING

Convert some drivers who export a single string as class attribute
to the new class_attr_string functions. This removes redundant
code all over.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Andi Kleen and committed by
Greg Kroah-Hartman
0933e2d9 869dfc87

+27 -57
+8 -11
drivers/gpu/drm/drm_sysfs.c
··· 70 70 return 0; 71 71 } 72 72 73 - /* Display the version of drm_core. This doesn't work right in current design */ 74 - static ssize_t version_show(struct class *dev, struct class_attribute *attr, 75 - char *buf) 76 - { 77 - return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR, 78 - CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE); 79 - } 80 - 81 73 static char *drm_devnode(struct device *dev, mode_t *mode) 82 74 { 83 75 return kasprintf(GFP_KERNEL, "dri/%s", dev_name(dev)); 84 76 } 85 77 86 - static CLASS_ATTR(version, S_IRUGO, version_show, NULL); 78 + static CLASS_ATTR_STRING(version, S_IRUGO, 79 + CORE_NAME " " 80 + __stringify(CORE_MAJOR) "." 81 + __stringify(CORE_MINOR) "." 82 + __stringify(CORE_PATCHLEVEL) " " 83 + CORE_DATE); 87 84 88 85 /** 89 86 * drm_sysfs_create - create a struct drm_sysfs_class structure ··· 107 110 class->suspend = drm_class_suspend; 108 111 class->resume = drm_class_resume; 109 112 110 - err = class_create_file(class, &class_attr_version); 113 + err = class_create_file(class, &class_attr_version.attr); 111 114 if (err) 112 115 goto err_out_class; 113 116 ··· 130 133 { 131 134 if ((drm_class == NULL) || (IS_ERR(drm_class))) 132 135 return; 133 - class_remove_file(drm_class, &class_attr_version); 136 + class_remove_file(drm_class, &class_attr_version.attr); 134 137 class_destroy(drm_class); 135 138 } 136 139
+5 -10
drivers/infiniband/core/ucm.c
··· 1336 1336 device_unregister(&ucm_dev->dev); 1337 1337 } 1338 1338 1339 - static ssize_t show_abi_version(struct class *class, 1340 - struct class_attribute *attr, 1341 - char *buf) 1342 - { 1343 - return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION); 1344 - } 1345 - static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL); 1339 + static CLASS_ATTR_STRING(abi_version, S_IRUGO, 1340 + __stringify(IB_USER_CM_ABI_VERSION)); 1346 1341 1347 1342 static int __init ib_ucm_init(void) 1348 1343 { ··· 1350 1355 goto error1; 1351 1356 } 1352 1357 1353 - ret = class_create_file(&cm_class, &class_attr_abi_version); 1358 + ret = class_create_file(&cm_class, &class_attr_abi_version.attr); 1354 1359 if (ret) { 1355 1360 printk(KERN_ERR "ucm: couldn't create abi_version attribute\n"); 1356 1361 goto error2; ··· 1364 1369 return 0; 1365 1370 1366 1371 error3: 1367 - class_remove_file(&cm_class, &class_attr_abi_version); 1372 + class_remove_file(&cm_class, &class_attr_abi_version.attr); 1368 1373 error2: 1369 1374 unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); 1370 1375 error1: ··· 1374 1379 static void __exit ib_ucm_cleanup(void) 1375 1380 { 1376 1381 ib_unregister_client(&ucm_client); 1377 - class_remove_file(&cm_class, &class_attr_abi_version); 1382 + class_remove_file(&cm_class, &class_attr_abi_version.attr); 1378 1383 unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); 1379 1384 if (overflow_maj) 1380 1385 unregister_chrdev_region(overflow_maj, IB_UCM_MAX_DEVICES);
+3 -8
drivers/infiniband/core/user_mad.c
··· 965 965 } 966 966 static DEVICE_ATTR(port, S_IRUGO, show_port, NULL); 967 967 968 - static ssize_t show_abi_version(struct class *class, 969 - struct class_attribute *attr, 970 - char *buf) 971 - { 972 - return sprintf(buf, "%d\n", IB_USER_MAD_ABI_VERSION); 973 - } 974 - static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL); 968 + static CLASS_ATTR_STRING(abi_version, S_IRUGO, 969 + __stringify(IB_USER_MAD_ABI_VERSION)); 975 970 976 971 static dev_t overflow_maj; 977 972 static DECLARE_BITMAP(overflow_map, IB_UMAD_MAX_PORTS); ··· 1191 1196 goto out_chrdev; 1192 1197 } 1193 1198 1194 - ret = class_create_file(umad_class, &class_attr_abi_version); 1199 + ret = class_create_file(umad_class, &class_attr_abi_version.attr); 1195 1200 if (ret) { 1196 1201 printk(KERN_ERR "user_mad: couldn't create abi_version attribute\n"); 1197 1202 goto out_class;
+3 -8
drivers/infiniband/core/uverbs_main.c
··· 691 691 } 692 692 static DEVICE_ATTR(abi_version, S_IRUGO, show_dev_abi_version, NULL); 693 693 694 - static ssize_t show_abi_version(struct class *class, 695 - struct class_attribute *attr, 696 - char *buf) 697 - { 698 - return sprintf(buf, "%d\n", IB_USER_VERBS_ABI_VERSION); 699 - } 700 - static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL); 694 + static CLASS_ATTR_STRING(abi_version, S_IRUGO, 695 + __stringify(IB_USER_VERBS_ABI_VERSION)); 701 696 702 697 static dev_t overflow_maj; 703 698 static DECLARE_BITMAP(overflow_map, IB_UVERBS_MAX_DEVICES); ··· 838 843 goto out_chrdev; 839 844 } 840 845 841 - ret = class_create_file(uverbs_class, &class_attr_abi_version); 846 + ret = class_create_file(uverbs_class, &class_attr_abi_version.attr); 842 847 if (ret) { 843 848 printk(KERN_ERR "user_verbs: couldn't create abi_version attribute\n"); 844 849 goto out_class;
+4 -9
drivers/misc/phantom.c
··· 497 497 .resume = phantom_resume 498 498 }; 499 499 500 - static ssize_t phantom_show_version(struct class *cls, struct class_attribute *attr, char *buf) 501 - { 502 - return sprintf(buf, PHANTOM_VERSION "\n"); 503 - } 504 - 505 - static CLASS_ATTR(version, 0444, phantom_show_version, NULL); 500 + static CLASS_ATTR_STRING(version, 0444, PHANTOM_VERSION); 506 501 507 502 static int __init phantom_init(void) 508 503 { ··· 510 515 printk(KERN_ERR "phantom: can't register phantom class\n"); 511 516 goto err; 512 517 } 513 - retval = class_create_file(phantom_class, &class_attr_version); 518 + retval = class_create_file(phantom_class, &class_attr_version.attr); 514 519 if (retval) { 515 520 printk(KERN_ERR "phantom: can't create sysfs version file\n"); 516 521 goto err_class; ··· 536 541 err_unchr: 537 542 unregister_chrdev_region(dev, PHANTOM_MAX_MINORS); 538 543 err_attr: 539 - class_remove_file(phantom_class, &class_attr_version); 544 + class_remove_file(phantom_class, &class_attr_version.attr); 540 545 err_class: 541 546 class_destroy(phantom_class); 542 547 err: ··· 549 554 550 555 unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS); 551 556 552 - class_remove_file(phantom_class, &class_attr_version); 557 + class_remove_file(phantom_class, &class_attr_version.attr); 553 558 class_destroy(phantom_class); 554 559 555 560 pr_debug("phantom: module successfully removed\n");
+4 -11
drivers/staging/asus_oled/asus_oled.c
··· 770 770 .id_table = id_table, 771 771 }; 772 772 773 - static ssize_t version_show(struct class *dev, 774 - struct class_attribute *attr, 775 - char *buf) 776 - { 777 - return sprintf(buf, ASUS_OLED_UNDERSCORE_NAME " %s\n", 778 - ASUS_OLED_VERSION); 779 - } 780 - 781 - static CLASS_ATTR(version, S_IRUGO, version_show, NULL); 773 + static CLASS_ATTR_STRING(version, S_IRUGO, 774 + ASUS_OLED_UNDERSCORE_NAME " " ASUS_OLED_VERSION); 782 775 783 776 static int __init asus_oled_init(void) 784 777 { ··· 783 790 return PTR_ERR(oled_class); 784 791 } 785 792 786 - retval = class_create_file(oled_class, &class_attr_version); 793 + retval = class_create_file(oled_class, &class_attr_version.attr); 787 794 if (retval) { 788 795 err("Error creating class version file"); 789 796 goto error; ··· 805 812 806 813 static void __exit asus_oled_exit(void) 807 814 { 808 - class_remove_file(oled_class, &class_attr_version); 815 + class_remove_file(oled_class, &class_attr_version.attr); 809 816 class_destroy(oled_class); 810 817 811 818 usb_deregister(&oled_driver);