Commit af5ca3f4ec5cc4432a42a73b050dd8898ce8fd00

Authored by Kay Sievers
Committed by Greg Kroah-Hartman
1 parent 528a4bf1d5

Driver core: change sysdev classes to use dynamic kobject names

All kobjects require a dynamically allocated name now. We no longer
need to keep track if the name is statically assigned, we can just
unconditionally free() all kobject names on cleanup.

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 55 changed files with 62 additions and 73 deletions Side-by-side Diff

arch/arm/kernel/time.c
... ... @@ -195,7 +195,7 @@
195 195 }
196 196  
197 197 static struct sysdev_class leds_sysclass = {
198   - set_kset_name("leds"),
  198 + .name = "leds",
199 199 .shutdown = leds_shutdown,
200 200 .suspend = leds_suspend,
201 201 .resume = leds_resume,
... ... @@ -369,7 +369,7 @@
369 369 #endif
370 370  
371 371 static struct sysdev_class timer_sysclass = {
372   - set_kset_name("timer"),
  372 + .name = "timer",
373 373 .suspend = timer_suspend,
374 374 .resume = timer_resume,
375 375 };
arch/arm/mach-integrator/integrator_ap.c
... ... @@ -214,7 +214,7 @@
214 214 #endif
215 215  
216 216 static struct sysdev_class irq_class = {
217   - set_kset_name("irq"),
  217 + .name = "irq",
218 218 .suspend = irq_suspend,
219 219 .resume = irq_resume,
220 220 };
arch/arm/mach-pxa/cm-x270.c
... ... @@ -566,7 +566,7 @@
566 566 }
567 567  
568 568 static struct sysdev_class cmx270_pm_sysclass = {
569   - set_kset_name("pm"),
  569 + .name = "pm",
570 570 .resume = cmx270_resume,
571 571 .suspend = cmx270_suspend,
572 572 };
arch/arm/mach-pxa/lpd270.c
... ... @@ -122,7 +122,7 @@
122 122 }
123 123  
124 124 static struct sysdev_class lpd270_irq_sysclass = {
125   - set_kset_name("cpld_irq"),
  125 + .name = "cpld_irq",
126 126 .resume = lpd270_irq_resume,
127 127 };
128 128  
arch/arm/mach-pxa/lubbock.c
... ... @@ -126,7 +126,7 @@
126 126 }
127 127  
128 128 static struct sysdev_class lubbock_irq_sysclass = {
129   - set_kset_name("cpld_irq"),
  129 + .name = "cpld_irq",
130 130 .resume = lubbock_irq_resume,
131 131 };
132 132  
arch/arm/mach-pxa/mainstone.c
... ... @@ -120,7 +120,7 @@
120 120 }
121 121  
122 122 static struct sysdev_class mainstone_irq_sysclass = {
123   - set_kset_name("cpld_irq"),
  123 + .name = "cpld_irq",
124 124 .resume = mainstone_irq_resume,
125 125 };
126 126  
arch/arm/mach-s3c2410/s3c2410.c
... ... @@ -100,7 +100,7 @@
100 100 }
101 101  
102 102 struct sysdev_class s3c2410_sysclass = {
103   - set_kset_name("s3c2410-core"),
  103 + .name = "s3c2410-core",
104 104 };
105 105  
106 106 static struct sys_device s3c2410_sysdev = {
arch/arm/mach-s3c2412/s3c2412.c
... ... @@ -196,7 +196,7 @@
196 196 */
197 197  
198 198 struct sysdev_class s3c2412_sysclass = {
199   - set_kset_name("s3c2412-core"),
  199 + .name = "s3c2412-core",
200 200 };
201 201  
202 202 static int __init s3c2412_core_init(void)
arch/arm/mach-s3c2440/mach-osiris.c
... ... @@ -312,7 +312,7 @@
312 312 #endif
313 313  
314 314 static struct sysdev_class osiris_pm_sysclass = {
315   - set_kset_name("mach-osiris"),
  315 + .name = "mach-osiris",
316 316 .suspend = osiris_pm_suspend,
317 317 .resume = osiris_pm_resume,
318 318 };
arch/arm/mach-s3c2443/s3c2443.c
... ... @@ -43,7 +43,7 @@
43 43 };
44 44  
45 45 struct sysdev_class s3c2443_sysclass = {
46   - set_kset_name("s3c2443-core"),
  46 + .name = "s3c2443-core",
47 47 };
48 48  
49 49 static struct sys_device s3c2443_sysdev = {
arch/arm/mach-sa1100/irq.c
... ... @@ -283,7 +283,7 @@
283 283 }
284 284  
285 285 static struct sysdev_class sa1100irq_sysclass = {
286   - set_kset_name("sa11x0-irq"),
  286 + .name = "sa11x0-irq",
287 287 .suspend = sa1100irq_suspend,
288 288 .resume = sa1100irq_resume,
289 289 };
arch/arm/oprofile/common.c
... ... @@ -96,7 +96,7 @@
96 96 }
97 97  
98 98 static struct sysdev_class oprofile_sysclass = {
99   - set_kset_name("oprofile"),
  99 + .name = "oprofile",
100 100 .resume = op_arm_resume,
101 101 .suspend = op_arm_suspend,
102 102 };
arch/arm/plat-omap/gpio.c
... ... @@ -1455,7 +1455,7 @@
1455 1455 }
1456 1456  
1457 1457 static struct sysdev_class omap_gpio_sysclass = {
1458   - set_kset_name("gpio"),
  1458 + .name = "gpio",
1459 1459 .suspend = omap_gpio_suspend,
1460 1460 .resume = omap_gpio_resume,
1461 1461 };
arch/arm/plat-s3c24xx/dma.c
... ... @@ -1265,7 +1265,7 @@
1265 1265 #endif /* CONFIG_PM */
1266 1266  
1267 1267 struct sysdev_class dma_sysclass = {
1268   - set_kset_name("s3c24xx-dma"),
  1268 + .name = "s3c24xx-dma",
1269 1269 .suspend = s3c2410_dma_suspend,
1270 1270 .resume = s3c2410_dma_resume,
1271 1271 };
arch/arm/plat-s3c24xx/s3c244x.c
... ... @@ -151,13 +151,13 @@
151 151 /* Since the S3C2442 and S3C2440 share items, put both sysclasses here */
152 152  
153 153 struct sysdev_class s3c2440_sysclass = {
154   - set_kset_name("s3c2440-core"),
  154 + .name = "s3c2440-core",
155 155 .suspend = s3c244x_suspend,
156 156 .resume = s3c244x_resume
157 157 };
158 158  
159 159 struct sysdev_class s3c2442_sysclass = {
160   - set_kset_name("s3c2442-core"),
  160 + .name = "s3c2442-core",
161 161 .suspend = s3c244x_suspend,
162 162 .resume = s3c244x_resume
163 163 };
arch/avr32/kernel/time.c
... ... @@ -214,7 +214,7 @@
214 214 }
215 215  
216 216 static struct sysdev_class timer_class = {
217   - set_kset_name("timer"),
  217 + .name = "timer",
218 218 };
219 219  
220 220 static struct sys_device timer_device = {
arch/mips/kernel/i8259.c
... ... @@ -238,7 +238,7 @@
238 238 }
239 239  
240 240 static struct sysdev_class i8259_sysdev_class = {
241   - set_kset_name("i8259"),
  241 + .name = "i8259",
242 242 .resume = i8259A_resume,
243 243 .shutdown = i8259A_shutdown,
244 244 };
arch/powerpc/platforms/cell/spu_base.c
... ... @@ -459,7 +459,7 @@
459 459 }
460 460  
461 461 static struct sysdev_class spu_sysdev_class = {
462   - set_kset_name("spu"),
  462 + .name = "spu",
463 463 .shutdown = spu_shutdown,
464 464 };
465 465  
arch/powerpc/platforms/powermac/pic.c
... ... @@ -663,7 +663,7 @@
663 663 #endif /* CONFIG_PM && CONFIG_PPC32 */
664 664  
665 665 static struct sysdev_class pmacpic_sysclass = {
666   - set_kset_name("pmac_pic"),
  666 + .name = "pmac_pic",
667 667 };
668 668  
669 669 static struct sys_device device_pmacpic = {
arch/powerpc/sysdev/ipic.c
... ... @@ -725,7 +725,7 @@
725 725 }
726 726  
727 727 static struct sysdev_class ipic_sysclass = {
728   - set_kset_name("ipic"),
  728 + .name = "ipic",
729 729 };
730 730  
731 731 static struct sys_device device_ipic = {
arch/powerpc/sysdev/mpic.c
... ... @@ -1584,7 +1584,7 @@
1584 1584 .resume = mpic_resume,
1585 1585 .suspend = mpic_suspend,
1586 1586 #endif
1587   - set_kset_name("mpic"),
  1587 + .name = "mpic",
1588 1588 };
1589 1589  
1590 1590 static int mpic_init_sys(void)
arch/powerpc/sysdev/qe_lib/qe_ic.c
... ... @@ -483,7 +483,7 @@
483 483 }
484 484  
485 485 static struct sysdev_class qe_ic_sysclass = {
486   - set_kset_name("qe_ic"),
  486 + .name = "qe_ic",
487 487 };
488 488  
489 489 static struct sys_device device_qe_ic = {
arch/ppc/syslib/ipic.c
... ... @@ -614,7 +614,7 @@
614 614 }
615 615  
616 616 static struct sysdev_class ipic_sysclass = {
617   - set_kset_name("ipic"),
  617 + .name = "ipic",
618 618 };
619 619  
620 620 static struct sys_device device_ipic = {
arch/ppc/syslib/open_pic.c
... ... @@ -1043,7 +1043,7 @@
1043 1043 #endif /* CONFIG_PM */
1044 1044  
1045 1045 static struct sysdev_class openpic_sysclass = {
1046   - set_kset_name("openpic"),
  1046 + .name = "openpic",
1047 1047 };
1048 1048  
1049 1049 static struct sys_device device_openpic = {
arch/ppc/syslib/open_pic2.c
... ... @@ -666,7 +666,7 @@
666 666  
667 667 /* HACK ALERT */
668 668 static struct sysdev_class openpic2_sysclass = {
669   - set_kset_name("openpic2"),
  669 + .name = "openpic2",
670 670 };
671 671  
672 672 static struct sys_device device_openpic2 = {
arch/s390/kernel/time.c
... ... @@ -1145,7 +1145,7 @@
1145 1145 * Sysfs interface functions
1146 1146 */
1147 1147 static struct sysdev_class etr_sysclass = {
1148   - set_kset_name("etr")
  1148 + .name = "etr",
1149 1149 };
1150 1150  
1151 1151 static struct sys_device etr_port0_dev = {
arch/sh/drivers/dma/dma-sysfs.c
... ... @@ -19,7 +19,7 @@
19 19 #include <asm/dma.h>
20 20  
21 21 static struct sysdev_class dma_sysclass = {
22   - set_kset_name("dma"),
  22 + .name = "dma",
23 23 };
24 24 EXPORT_SYMBOL(dma_sysclass);
25 25  
arch/sh/kernel/time.c
... ... @@ -174,7 +174,7 @@
174 174 #endif
175 175  
176 176 static struct sysdev_class timer_sysclass = {
177   - set_kset_name("timer"),
  177 + .name = "timer",
178 178 .suspend = timer_suspend,
179 179 .resume = timer_resume,
180 180 };
arch/x86/kernel/apic_32.c
... ... @@ -1530,7 +1530,7 @@
1530 1530 */
1531 1531  
1532 1532 static struct sysdev_class lapic_sysclass = {
1533   - set_kset_name("lapic"),
  1533 + .name = "lapic",
1534 1534 .resume = lapic_resume,
1535 1535 .suspend = lapic_suspend,
1536 1536 };
arch/x86/kernel/apic_64.c
... ... @@ -639,7 +639,7 @@
639 639 }
640 640  
641 641 static struct sysdev_class lapic_sysclass = {
642   - set_kset_name("lapic"),
  642 + .name = "lapic",
643 643 .resume = lapic_resume,
644 644 .suspend = lapic_suspend,
645 645 };
arch/x86/kernel/cpu/mcheck/mce_64.c
... ... @@ -745,7 +745,7 @@
745 745  
746 746 static struct sysdev_class mce_sysclass = {
747 747 .resume = mce_resume,
748   - set_kset_name("machinecheck"),
  748 + .name = "machinecheck",
749 749 };
750 750  
751 751 DEFINE_PER_CPU(struct sys_device, device_mce);
arch/x86/kernel/i8237.c
... ... @@ -51,7 +51,7 @@
51 51 }
52 52  
53 53 static struct sysdev_class i8237_sysdev_class = {
54   - set_kset_name("i8237"),
  54 + .name = "i8237",
55 55 .suspend = i8237A_suspend,
56 56 .resume = i8237A_resume,
57 57 };
arch/x86/kernel/i8259_32.c
... ... @@ -258,7 +258,7 @@
258 258 }
259 259  
260 260 static struct sysdev_class i8259_sysdev_class = {
261   - set_kset_name("i8259"),
  261 + .name = "i8259",
262 262 .suspend = i8259A_suspend,
263 263 .resume = i8259A_resume,
264 264 .shutdown = i8259A_shutdown,
arch/x86/kernel/i8259_64.c
... ... @@ -370,7 +370,7 @@
370 370 }
371 371  
372 372 static struct sysdev_class i8259_sysdev_class = {
373   - set_kset_name("i8259"),
  373 + .name = "i8259",
374 374 .suspend = i8259A_suspend,
375 375 .resume = i8259A_resume,
376 376 .shutdown = i8259A_shutdown,
arch/x86/kernel/io_apic_32.c
... ... @@ -2401,7 +2401,7 @@
2401 2401 }
2402 2402  
2403 2403 static struct sysdev_class ioapic_sysdev_class = {
2404   - set_kset_name("ioapic"),
  2404 + .name = "ioapic",
2405 2405 .suspend = ioapic_suspend,
2406 2406 .resume = ioapic_resume,
2407 2407 };
arch/x86/kernel/io_apic_64.c
... ... @@ -1850,7 +1850,7 @@
1850 1850 }
1851 1851  
1852 1852 static struct sysdev_class ioapic_sysdev_class = {
1853   - set_kset_name("ioapic"),
  1853 + .name = "ioapic",
1854 1854 .suspend = ioapic_suspend,
1855 1855 .resume = ioapic_resume,
1856 1856 };
arch/x86/kernel/nmi_32.c
... ... @@ -176,7 +176,7 @@
176 176  
177 177  
178 178 static struct sysdev_class nmi_sysclass = {
179   - set_kset_name("lapic_nmi"),
  179 + .name = "lapic_nmi",
180 180 .resume = lapic_nmi_resume,
181 181 .suspend = lapic_nmi_suspend,
182 182 };
arch/x86/kernel/nmi_64.c
... ... @@ -211,7 +211,7 @@
211 211 }
212 212  
213 213 static struct sysdev_class nmi_sysclass = {
214   - set_kset_name("lapic_nmi"),
  214 + .name = "lapic_nmi",
215 215 .resume = lapic_nmi_resume,
216 216 .suspend = lapic_nmi_suspend,
217 217 };
arch/x86/oprofile/nmi_int.c
... ... @@ -51,7 +51,7 @@
51 51  
52 52  
53 53 static struct sysdev_class oprofile_sysclass = {
54   - set_kset_name("oprofile"),
  54 + .name = "oprofile",
55 55 .resume = nmi_resume,
56 56 .suspend = nmi_suspend,
57 57 };
drivers/acpi/pci_link.c
... ... @@ -911,7 +911,7 @@
911 911  
912 912 /* FIXME: we will remove this interface after all drivers call pci_disable_device */
913 913 static struct sysdev_class irqrouter_sysdev_class = {
914   - set_kset_name("irqrouter"),
  914 + .name = "irqrouter",
915 915 .resume = irqrouter_resume,
916 916 };
917 917  
drivers/base/class.c
... ... @@ -466,7 +466,6 @@
466 466 * entirely soon.
467 467 */
468 468 static struct kset class_obj_subsys = {
469   - .kobj = { .k_name = "class_obj", },
470 469 .uevent_ops = &class_uevent_ops,
471 470 };
472 471  
... ... @@ -872,6 +871,7 @@
872 871 /* ick, this is ugly, the things we go through to keep from showing up
873 872 * in sysfs... */
874 873 kset_init(&class_obj_subsys);
  874 + kobject_set_name(&class_obj_subsys.kobj, "class_obj");
875 875 if (!class_obj_subsys.kobj.parent)
876 876 class_obj_subsys.kobj.parent = &class_obj_subsys.kobj;
877 877 return 0;
... ... @@ -14,7 +14,7 @@
14 14 #include "base.h"
15 15  
16 16 struct sysdev_class cpu_sysdev_class = {
17   - set_kset_name("cpu"),
  17 + .name = "cpu",
18 18 };
19 19 EXPORT_SYMBOL(cpu_sysdev_class);
20 20  
drivers/base/memory.c
... ... @@ -26,7 +26,7 @@
26 26 #define MEMORY_CLASS_NAME "memory"
27 27  
28 28 static struct sysdev_class memory_sysdev_class = {
29   - set_kset_name(MEMORY_CLASS_NAME),
  29 + .name = MEMORY_CLASS_NAME,
30 30 };
31 31  
32 32 static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj)
... ... @@ -15,7 +15,7 @@
15 15 #include <linux/device.h>
16 16  
17 17 static struct sysdev_class node_class = {
18   - set_kset_name("node"),
  18 + .name = "node",
19 19 };
20 20  
21 21  
... ... @@ -136,6 +136,7 @@
136 136 cls->kset.kobj.parent = &system_kset->kobj;
137 137 cls->kset.kobj.ktype = &ktype_sysdev_class;
138 138 cls->kset.kobj.kset = system_kset;
  139 + kobject_set_name(&cls->kset.kobj, cls->name);
139 140 return kset_register(&cls->kset);
140 141 }
141 142  
drivers/edac/edac_module.c
... ... @@ -31,7 +31,7 @@
31 31 * need to export to other files in this modules
32 32 */
33 33 static struct sysdev_class edac_class = {
34   - set_kset_name("edac"),
  34 + .name = "edac",
35 35 };
36 36 static int edac_class_valid;
37 37  
drivers/kvm/kvm_main.c
... ... @@ -3451,7 +3451,7 @@
3451 3451 }
3452 3452  
3453 3453 static struct sysdev_class kvm_sysdev_class = {
3454   - set_kset_name("kvm"),
  3454 + .name = "kvm",
3455 3455 .suspend = kvm_suspend,
3456 3456 .resume = kvm_resume,
3457 3457 };
drivers/macintosh/via-pmu.c
... ... @@ -2796,7 +2796,7 @@
2796 2796 #endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */
2797 2797  
2798 2798 static struct sysdev_class pmu_sysclass = {
2799   - set_kset_name("pmu"),
  2799 + .name = "pmu",
2800 2800 };
2801 2801  
2802 2802 static struct sys_device device_pmu = {
drivers/scsi/libsas/sas_scsi_host.c
... ... @@ -464,7 +464,7 @@
464 464 res = sas_phy_reset(phy, 1);
465 465 if (res)
466 466 SAS_DPRINTK("Bus reset of %s failed 0x%x\n",
467   - phy->dev.kobj.k_name,
  467 + kobject_name(&phy->dev.kobj),
468 468 res);
469 469 if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE)
470 470 return SUCCESS;
include/linux/kobject.h
... ... @@ -61,7 +61,7 @@
61 61 };
62 62  
63 63 struct kobject {
64   - const char * k_name;
  64 + const char *name;
65 65 struct kref kref;
66 66 struct list_head entry;
67 67 struct kobject * parent;
... ... @@ -69,7 +69,6 @@
69 69 struct kobj_type * ktype;
70 70 struct sysfs_dirent * sd;
71 71 unsigned int state_initialized:1;
72   - unsigned int state_name_set:1;
73 72 unsigned int state_in_sysfs:1;
74 73 unsigned int state_add_uevent_sent:1;
75 74 unsigned int state_remove_uevent_sent:1;
... ... @@ -80,7 +79,7 @@
80 79  
81 80 static inline const char * kobject_name(const struct kobject * kobj)
82 81 {
83   - return kobj->k_name;
  82 + return kobj->name;
84 83 }
85 84  
86 85 extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
... ... @@ -188,14 +187,6 @@
188 187 }
189 188  
190 189 extern struct kobject * kset_find_obj(struct kset *, const char *);
191   -
192   -
193   -/*
194   - * Use this when initializing an embedded kset with no other
195   - * fields to initialize.
196   - */
197   -#define set_kset_name(str) .kset = { .kobj = { .k_name = str } }
198   -
199 190  
200 191 /* The global /sys/kernel/ kobject for people to chain off of */
201 192 extern struct kobject *kernel_kobj;
include/linux/sysdev.h
... ... @@ -29,6 +29,7 @@
29 29 struct sys_device;
30 30  
31 31 struct sysdev_class {
  32 + const char *name;
32 33 struct list_head drivers;
33 34  
34 35 /* Default operations for these types of devices */
kernel/rtmutex-tester.c
... ... @@ -394,7 +394,7 @@
394 394 static SYSDEV_ATTR(command, 0600, NULL, sysfs_test_command);
395 395  
396 396 static struct sysdev_class rttest_sysclass = {
397   - set_kset_name("rttest"),
  397 + .name = "rttest",
398 398 };
399 399  
400 400 static int init_test_thread(int id)
kernel/time/clocksource.c
... ... @@ -441,7 +441,7 @@
441 441 sysfs_show_available_clocksources, NULL);
442 442  
443 443 static struct sysdev_class clocksource_sysclass = {
444   - set_kset_name("clocksource"),
  444 + .name = "clocksource",
445 445 };
446 446  
447 447 static struct sys_device device_clocksource = {
kernel/time/timekeeping.c
... ... @@ -335,9 +335,9 @@
335 335  
336 336 /* sysfs resume/suspend bits for timekeeping */
337 337 static struct sysdev_class timekeeping_sysclass = {
  338 + .name = "timekeeping",
338 339 .resume = timekeeping_resume,
339 340 .suspend = timekeeping_suspend,
340   - set_kset_name("timekeeping"),
341 341 };
342 342  
343 343 static struct sys_device device_timer = {
... ... @@ -165,7 +165,7 @@
165 165 if (!kobj)
166 166 return -ENOENT;
167 167  
168   - if (!kobj->k_name || !kobj->k_name[0]) {
  168 + if (!kobj->name || !kobj->name[0]) {
169 169 pr_debug("kobject: (%p): attempted to be registered with empty "
170 170 "name!\n", kobj);
171 171 WARN_ON(1);
172 172  
173 173  
... ... @@ -228,13 +228,11 @@
228 228 if (!name)
229 229 return -ENOMEM;
230 230  
231   -
232 231 /* Free the old name, if necessary. */
233   - kfree(kobj->k_name);
  232 + kfree(kobj->name);
234 233  
235 234 /* Now, set the new name */
236   - kobj->k_name = name;
237   - kobj->state_name_set = 1;
  235 + kobj->name = name;
238 236  
239 237 return 0;
240 238 }
... ... @@ -295,7 +293,6 @@
295 293 kref_init(&kobj->kref);
296 294 INIT_LIST_HEAD(&kobj->entry);
297 295 kobj->ktype = ktype;
298   - kobj->state_name_set = 0;
299 296 kobj->state_in_sysfs = 0;
300 297 kobj->state_add_uevent_sent = 0;
301 298 kobj->state_remove_uevent_sent = 0;
... ... @@ -551,8 +548,7 @@
551 548 static void kobject_cleanup(struct kobject *kobj)
552 549 {
553 550 struct kobj_type *t = get_ktype(kobj);
554   - const char *name = kobj->k_name;
555   - int name_set = kobj->state_name_set;
  551 + const char *name = kobj->name;
556 552  
557 553 pr_debug("kobject: '%s' (%p): %s\n",
558 554 kobject_name(kobj), kobj, __FUNCTION__);
... ... @@ -583,7 +579,7 @@
583 579 }
584 580  
585 581 /* free name if we allocated it */
586   - if (name_set && name) {
  582 + if (name) {
587 583 pr_debug("kobject: '%s': free name\n", name);
588 584 kfree(name);
589 585 }