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

EDAC: Rip out the edac_subsys reference counting

This was really dumb - reference counting for the main EDAC sysfs
object. While we could've simply registered it as the first thing in the
module init path and then hand it around to what needs it.

Do that and rip out all the code around it, thus simplifying the whole
handling significantly.

Move the edac_subsys node back to edac_module.c.

Signed-off-by: Borislav Petkov <bp@suse.de>

+43 -56
+1 -5
drivers/edac/edac_device_sysfs.c
··· 256 256 257 257 if (!try_module_get(edac_dev->owner)) { 258 258 err = -ENODEV; 259 - goto err_mod_get; 259 + goto err_out; 260 260 } 261 261 262 262 /* register */ ··· 282 282 err_kobj_reg: 283 283 module_put(edac_dev->owner); 284 284 285 - err_mod_get: 286 - edac_put_sysfs_subsys(); 287 - 288 285 err_out: 289 286 return err; 290 287 } ··· 303 306 * b) 'kfree' the memory 304 307 */ 305 308 kobject_put(&dev->kobj); 306 - edac_put_sysfs_subsys(); 307 309 } 308 310 309 311 /* edac_dev -> instance information */
+1 -4
drivers/edac/edac_mc_sysfs.c
··· 1039 1039 mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL); 1040 1040 if (!mci_pdev) { 1041 1041 err = -ENOMEM; 1042 - goto out_put_sysfs; 1042 + goto out; 1043 1043 } 1044 1044 1045 1045 mci_pdev->bus = edac_subsys; ··· 1057 1057 1058 1058 out_dev_free: 1059 1059 kfree(mci_pdev); 1060 - out_put_sysfs: 1061 - edac_put_sysfs_subsys(); 1062 1060 out: 1063 1061 return err; 1064 1062 } ··· 1064 1066 void edac_mc_sysfs_exit(void) 1065 1067 { 1066 1068 device_unregister(mci_pdev); 1067 - edac_put_sysfs_subsys(); 1068 1069 }
+40
drivers/edac/edac_module.c
··· 92 92 } 93 93 94 94 /* 95 + * sysfs object: /sys/devices/system/edac 96 + * need to export to other files 97 + */ 98 + struct bus_type edac_subsys = { 99 + .name = "edac", 100 + .dev_name = "edac", 101 + }; 102 + EXPORT_SYMBOL_GPL(edac_subsys); 103 + 104 + static int edac_subsys_init(void) 105 + { 106 + int err; 107 + 108 + /* create the /sys/devices/system/edac directory */ 109 + err = subsys_system_register(&edac_subsys, NULL); 110 + if (err) 111 + printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n"); 112 + 113 + return err; 114 + } 115 + 116 + static void edac_subsys_exit(void) 117 + { 118 + bus_unregister(&edac_subsys); 119 + } 120 + 121 + /* return pointer to the 'edac' node in sysfs */ 122 + struct bus_type *edac_get_sysfs_subsys(void) 123 + { 124 + return &edac_subsys; 125 + } 126 + EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys); 127 + /* 95 128 * edac_init 96 129 * module initialization entry point 97 130 */ ··· 133 100 int err = 0; 134 101 135 102 edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n"); 103 + 104 + err = edac_subsys_init(); 105 + if (err) 106 + return err; 136 107 137 108 /* 138 109 * Harvest and clear any boot/initialization PCI parity errors ··· 166 129 edac_mc_sysfs_exit(); 167 130 168 131 err_sysfs: 132 + edac_subsys_exit(); 133 + 169 134 return err; 170 135 } 171 136 ··· 183 144 edac_workqueue_teardown(); 184 145 edac_mc_sysfs_exit(); 185 146 edac_debugfs_exit(); 147 + edac_subsys_exit(); 186 148 } 187 149 188 150 /*
+1 -5
drivers/edac/edac_pci_sysfs.c
··· 364 364 if (!try_module_get(THIS_MODULE)) { 365 365 edac_dbg(1, "try_module_get() failed\n"); 366 366 err = -ENODEV; 367 - goto mod_get_fail; 367 + goto decrement_count_fail; 368 368 } 369 369 370 370 edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); ··· 399 399 kzalloc_fail: 400 400 module_put(THIS_MODULE); 401 401 402 - mod_get_fail: 403 - edac_put_sysfs_subsys(); 404 - 405 402 decrement_count_fail: 406 403 /* if are on this error exit, nothing to tear down */ 407 404 atomic_dec(&edac_pci_sysfs_refcount); ··· 423 426 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) { 424 427 edac_dbg(0, "called kobject_put on main kobj\n"); 425 428 kobject_put(edac_pci_top_main_kobj); 426 - edac_put_sysfs_subsys(); 427 429 } 428 430 } 429 431
-41
drivers/edac/edac_stub.c
··· 26 26 int edac_err_assert = 0; 27 27 EXPORT_SYMBOL_GPL(edac_err_assert); 28 28 29 - static atomic_t edac_subsys_valid = ATOMIC_INIT(0); 30 - 31 29 int edac_report_status = EDAC_REPORTING_ENABLED; 32 30 EXPORT_SYMBOL_GPL(edac_report_status); 33 31 ··· 66 68 edac_err_assert++; 67 69 } 68 70 EXPORT_SYMBOL_GPL(edac_atomic_assert_error); 69 - 70 - /* 71 - * sysfs object: /sys/devices/system/edac 72 - * need to export to other files 73 - */ 74 - struct bus_type edac_subsys = { 75 - .name = "edac", 76 - .dev_name = "edac", 77 - }; 78 - EXPORT_SYMBOL_GPL(edac_subsys); 79 - 80 - /* return pointer to the 'edac' node in sysfs */ 81 - struct bus_type *edac_get_sysfs_subsys(void) 82 - { 83 - int err = 0; 84 - 85 - if (atomic_read(&edac_subsys_valid)) 86 - goto out; 87 - 88 - /* create the /sys/devices/system/edac directory */ 89 - err = subsys_system_register(&edac_subsys, NULL); 90 - if (err) { 91 - printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n"); 92 - return NULL; 93 - } 94 - 95 - out: 96 - atomic_inc(&edac_subsys_valid); 97 - return &edac_subsys; 98 - } 99 - EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys); 100 - 101 - void edac_put_sysfs_subsys(void) 102 - { 103 - /* last user unregisters it */ 104 - if (atomic_dec_and_test(&edac_subsys_valid)) 105 - bus_unregister(&edac_subsys); 106 - } 107 - EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys);
-1
include/linux/edac.h
··· 33 33 extern int edac_handler_set(void); 34 34 extern void edac_atomic_assert_error(void); 35 35 extern struct bus_type *edac_get_sysfs_subsys(void); 36 - extern void edac_put_sysfs_subsys(void); 37 36 38 37 enum { 39 38 EDAC_REPORTING_ENABLED,