edac: core fix to use dynamic kobject

Static kobjects are not supported in linux kernel. Convert the
edac_pci_top_main_kobj from static to dynamic. This avoids the double
free of the edac_pci_top_main_kobj.name that we see on module reload of
the e752x edac driver (and probably others as well).

In addition Greg KH <greg@kroah.com> has pointed out that this code may be
cleaned up significantly. I will look at that as a follow-on patch, for
now, I just want the minimum fix to get this double-free oops bug
squashed...

Many thanks to Greg KH for his patience in showing me what the
Documentation/kobject.txt already said (oops)...

Signed-off-by: Arthur Jones <ajones@riverbed.com>
Signed-off-by: Doug Thompson <dougthompson@xmission.com>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Arthur Jones and committed by
Linus Torvalds
14cc571b b238e577

+21 -9
+21 -9
drivers/edac/edac_pci_sysfs.c
··· 28 28 static atomic_t pci_parity_count = ATOMIC_INIT(0); 29 29 static atomic_t pci_nonparity_count = ATOMIC_INIT(0); 30 30 31 - static struct kobject edac_pci_top_main_kobj; 31 + static struct kobject *edac_pci_top_main_kobj; 32 32 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0); 33 33 34 34 /* getter functions for the data variables */ ··· 83 83 pci = to_instance(kobj); 84 84 85 85 /* decrement reference count on top main kobj */ 86 - kobject_put(&edac_pci_top_main_kobj); 86 + kobject_put(edac_pci_top_main_kobj); 87 87 88 88 kfree(pci); /* Free the control struct */ 89 89 } ··· 166 166 * track the number of PCI instances we have, and thus nest 167 167 * properly on keeping the module loaded 168 168 */ 169 - main_kobj = kobject_get(&edac_pci_top_main_kobj); 169 + main_kobj = kobject_get(edac_pci_top_main_kobj); 170 170 if (!main_kobj) { 171 171 err = -ENODEV; 172 172 goto error_out; ··· 174 174 175 175 /* And now register this new kobject under the main kobj */ 176 176 err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance, 177 - &edac_pci_top_main_kobj, "pci%d", idx); 177 + edac_pci_top_main_kobj, "pci%d", idx); 178 178 if (err != 0) { 179 179 debugf2("%s() failed to register instance pci%d\n", 180 180 __func__, idx); 181 - kobject_put(&edac_pci_top_main_kobj); 181 + kobject_put(edac_pci_top_main_kobj); 182 182 goto error_out; 183 183 } 184 184 ··· 316 316 */ 317 317 static void edac_pci_release_main_kobj(struct kobject *kobj) 318 318 { 319 - 320 319 debugf0("%s() here to module_put(THIS_MODULE)\n", __func__); 320 + 321 + kfree(kobj); 321 322 322 323 /* last reference to top EDAC PCI kobject has been removed, 323 324 * NOW release our ref count on the core module ··· 370 369 goto decrement_count_fail; 371 370 } 372 371 372 + edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); 373 + if (!edac_pci_top_main_kobj) { 374 + debugf1("Failed to allocate\n"); 375 + err = -ENOMEM; 376 + goto kzalloc_fail; 377 + } 378 + 373 379 /* Instanstiate the pci object */ 374 - err = kobject_init_and_add(&edac_pci_top_main_kobj, &ktype_edac_pci_main_kobj, 380 + err = kobject_init_and_add(edac_pci_top_main_kobj, 381 + &ktype_edac_pci_main_kobj, 375 382 &edac_class->kset.kobj, "pci"); 376 383 if (err) { 377 384 debugf1("Failed to register '.../edac/pci'\n"); ··· 390 381 * for EDAC PCI, then edac_pci_main_kobj_teardown() 391 382 * must be used, for resources to be cleaned up properly 392 383 */ 393 - kobject_uevent(&edac_pci_top_main_kobj, KOBJ_ADD); 384 + kobject_uevent(edac_pci_top_main_kobj, KOBJ_ADD); 394 385 debugf1("Registered '.../edac/pci' kobject\n"); 395 386 396 387 return 0; 397 388 398 389 /* Error unwind statck */ 399 390 kobject_init_and_add_fail: 391 + kfree(edac_pci_top_main_kobj); 392 + 393 + kzalloc_fail: 400 394 module_put(THIS_MODULE); 401 395 402 396 decrement_count_fail: ··· 426 414 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) { 427 415 debugf0("%s() called kobject_put on main kobj\n", 428 416 __func__); 429 - kobject_put(&edac_pci_top_main_kobj); 417 + kobject_put(edac_pci_top_main_kobj); 430 418 } 431 419 } 432 420