device_attributes: add sysfs_attr_init() for dynamic attributes
authorWolfram Sang <w.sang@pengutronix.de>
Tue, 6 Apr 2010 21:34:52 +0000 (14:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 7 Apr 2010 15:38:03 +0000 (08:38 -0700)
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>
drivers/macintosh/windfarm_core.c
drivers/media/video/pvrusb2/pvrusb2-sysfs.c
drivers/platform/x86/intel_menlow.c
drivers/video/fsl-diu-fb.c

index c092354..ce88979 100644 (file)
@@ -210,6 +210,7 @@ int wf_register_control(struct wf_control *new_ct)
        kref_init(&new_ct->ref);
        list_add(&new_ct->link, &wf_controls);
 
+       sysfs_attr_init(&new_ct->attr.attr);
        new_ct->attr.attr.name = new_ct->name;
        new_ct->attr.attr.mode = 0644;
        new_ct->attr.show = wf_show_control;
index 6c23456..71f5056 100644 (file)
@@ -423,10 +423,12 @@ static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
 
        dip = kzalloc(sizeof(*dip),GFP_KERNEL);
        if (!dip) return;
+       sysfs_attr_init(&dip->attr_debugcmd.attr);
        dip->attr_debugcmd.attr.name = "debugcmd";
        dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
        dip->attr_debugcmd.show = debugcmd_show;
        dip->attr_debugcmd.store = debugcmd_store;
+       sysfs_attr_init(&dip->attr_debuginfo.attr);
        dip->attr_debuginfo.attr.name = "debuginfo";
        dip->attr_debuginfo.attr.mode = S_IRUGO;
        dip->attr_debuginfo.show = debuginfo_show;
@@ -644,6 +646,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
                return;
        }
 
+       sysfs_attr_init(&sfp->attr_v4l_minor_number.attr);
        sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
        sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
        sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
@@ -658,6 +661,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
                sfp->v4l_minor_number_created_ok = !0;
        }
 
+       sysfs_attr_init(&sfp->attr_v4l_radio_minor_number.attr);
        sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
        sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
        sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
@@ -672,6 +676,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
                sfp->v4l_radio_minor_number_created_ok = !0;
        }
 
+       sysfs_attr_init(&sfp->attr_unit_number.attr);
        sfp->attr_unit_number.attr.name = "unit_number";
        sfp->attr_unit_number.attr.mode = S_IRUGO;
        sfp->attr_unit_number.show = unit_number_show;
@@ -685,6 +690,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
                sfp->unit_number_created_ok = !0;
        }
 
+       sysfs_attr_init(&sfp->attr_bus_info.attr);
        sfp->attr_bus_info.attr.name = "bus_info_str";
        sfp->attr_bus_info.attr.mode = S_IRUGO;
        sfp->attr_bus_info.show = bus_info_show;
@@ -699,6 +705,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
                sfp->bus_info_created_ok = !0;
        }
 
+       sysfs_attr_init(&sfp->attr_hdw_name.attr);
        sfp->attr_hdw_name.attr.name = "device_hardware_type";
        sfp->attr_hdw_name.attr.mode = S_IRUGO;
        sfp->attr_hdw_name.show = hdw_name_show;
@@ -713,6 +720,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
                sfp->hdw_name_created_ok = !0;
        }
 
+       sysfs_attr_init(&sfp->attr_hdw_desc.attr);
        sfp->attr_hdw_desc.attr.name = "device_hardware_description";
        sfp->attr_hdw_desc.attr.mode = S_IRUGO;
        sfp->attr_hdw_desc.show = hdw_desc_show;
index 1190bad..2f795ce 100644 (file)
@@ -397,6 +397,7 @@ static int intel_menlow_add_one_attribute(char *name, int mode, void *show,
        if (!attr)
                return -ENOMEM;
 
+       sysfs_attr_init(&attr->attr.attr); /* That is consistent naming :D */
        attr->attr.attr.name = name;
        attr->attr.attr.mode = mode;
        attr->attr.show = show;
index 4637bcb..994358a 100644 (file)
@@ -1536,6 +1536,7 @@ static int __devinit fsl_diu_probe(struct of_device *ofdev,
                goto error;
        }
 
+       sysfs_attr_init(&machine_data->dev_attr.attr);
        machine_data->dev_attr.attr.name = "monitor";
        machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
        machine_data->dev_attr.show = show_monitor;