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

device_attributes: add sysfs_attr_init() for dynamic attributes

Made necessary by 6992f5334995af474c2b58d010d08bc597f0f2fe ("sysfs: Use
one lockdep class per sysfs attribute").

Prevents further "key xxx not in .data" bug-reports. Although some
attributes could probably be converted to static ones, this is left for
people having hardware to test.

Found by this semantic patch:

@ init @
type T;
identifier A;
@@

T {
...
struct device_attribute A;
...
};

@ main extends init @
expression E;
statement S;
identifier err;
T *name;
@@

... when != sysfs_attr_init(&name->A.attr);
(
+ sysfs_attr_init(&name->A.attr);
if (device_create_file(E, &name->A))
S
|
+ sysfs_attr_init(&name->A.attr);
err = device_create_file(E, &name->A);
)

While reviewing, I put the initialization to apropriate places.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Greg KH <gregkh@suse.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Mike Isely <isely@pobox.com>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Matthew Garrett <mjg@redhat.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Wolfram Sang and committed by
Linus Torvalds
12765517 975f8c56

+11
+1
drivers/macintosh/windfarm_core.c
··· 210 210 kref_init(&new_ct->ref); 211 211 list_add(&new_ct->link, &wf_controls); 212 212 213 + sysfs_attr_init(&new_ct->attr.attr); 213 214 new_ct->attr.attr.name = new_ct->name; 214 215 new_ct->attr.attr.mode = 0644; 215 216 new_ct->attr.show = wf_show_control;
+8
drivers/media/video/pvrusb2/pvrusb2-sysfs.c
··· 423 423 424 424 dip = kzalloc(sizeof(*dip),GFP_KERNEL); 425 425 if (!dip) return; 426 + sysfs_attr_init(&dip->attr_debugcmd.attr); 426 427 dip->attr_debugcmd.attr.name = "debugcmd"; 427 428 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP; 428 429 dip->attr_debugcmd.show = debugcmd_show; 429 430 dip->attr_debugcmd.store = debugcmd_store; 431 + sysfs_attr_init(&dip->attr_debuginfo.attr); 430 432 dip->attr_debuginfo.attr.name = "debuginfo"; 431 433 dip->attr_debuginfo.attr.mode = S_IRUGO; 432 434 dip->attr_debuginfo.show = debuginfo_show; ··· 646 644 return; 647 645 } 648 646 647 + sysfs_attr_init(&sfp->attr_v4l_minor_number.attr); 649 648 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; 650 649 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; 651 650 sfp->attr_v4l_minor_number.show = v4l_minor_number_show; ··· 661 658 sfp->v4l_minor_number_created_ok = !0; 662 659 } 663 660 661 + sysfs_attr_init(&sfp->attr_v4l_radio_minor_number.attr); 664 662 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number"; 665 663 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO; 666 664 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show; ··· 676 672 sfp->v4l_radio_minor_number_created_ok = !0; 677 673 } 678 674 675 + sysfs_attr_init(&sfp->attr_unit_number.attr); 679 676 sfp->attr_unit_number.attr.name = "unit_number"; 680 677 sfp->attr_unit_number.attr.mode = S_IRUGO; 681 678 sfp->attr_unit_number.show = unit_number_show; ··· 690 685 sfp->unit_number_created_ok = !0; 691 686 } 692 687 688 + sysfs_attr_init(&sfp->attr_bus_info.attr); 693 689 sfp->attr_bus_info.attr.name = "bus_info_str"; 694 690 sfp->attr_bus_info.attr.mode = S_IRUGO; 695 691 sfp->attr_bus_info.show = bus_info_show; ··· 705 699 sfp->bus_info_created_ok = !0; 706 700 } 707 701 702 + sysfs_attr_init(&sfp->attr_hdw_name.attr); 708 703 sfp->attr_hdw_name.attr.name = "device_hardware_type"; 709 704 sfp->attr_hdw_name.attr.mode = S_IRUGO; 710 705 sfp->attr_hdw_name.show = hdw_name_show; ··· 720 713 sfp->hdw_name_created_ok = !0; 721 714 } 722 715 716 + sysfs_attr_init(&sfp->attr_hdw_desc.attr); 723 717 sfp->attr_hdw_desc.attr.name = "device_hardware_description"; 724 718 sfp->attr_hdw_desc.attr.mode = S_IRUGO; 725 719 sfp->attr_hdw_desc.show = hdw_desc_show;
+1
drivers/platform/x86/intel_menlow.c
··· 397 397 if (!attr) 398 398 return -ENOMEM; 399 399 400 + sysfs_attr_init(&attr->attr.attr); /* That is consistent naming :D */ 400 401 attr->attr.attr.name = name; 401 402 attr->attr.attr.mode = mode; 402 403 attr->attr.show = show;
+1
drivers/video/fsl-diu-fb.c
··· 1536 1536 goto error; 1537 1537 } 1538 1538 1539 + sysfs_attr_init(&machine_data->dev_attr.attr); 1539 1540 machine_data->dev_attr.attr.name = "monitor"; 1540 1541 machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR; 1541 1542 machine_data->dev_attr.show = show_monitor;