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