]> git.karo-electronics.de Git - linux-beck.git/commitdiff
EDAC: Rip out the edac_subsys reference counting
authorBorislav Petkov <bp@suse.de>
Fri, 27 Nov 2015 10:40:43 +0000 (11:40 +0100)
committerBorislav Petkov <bp@suse.de>
Fri, 11 Dec 2015 15:56:39 +0000 (16:56 +0100)
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>
drivers/edac/edac_device_sysfs.c
drivers/edac/edac_mc_sysfs.c
drivers/edac/edac_module.c
drivers/edac/edac_pci_sysfs.c
drivers/edac/edac_stub.c
include/linux/edac.h

index fb68a06ad6837fcce67b3a3baefb98026ad146c3..1705271653749ba8ae1a9918dbf68c69b9f122cf 100644 (file)
@@ -256,7 +256,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
 
        if (!try_module_get(edac_dev->owner)) {
                err = -ENODEV;
-               goto err_mod_get;
+               goto err_out;
        }
 
        /* register */
@@ -282,9 +282,6 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
 err_kobj_reg:
        module_put(edac_dev->owner);
 
-err_mod_get:
-       edac_put_sysfs_subsys();
-
 err_out:
        return err;
 }
@@ -306,7 +303,6 @@ void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev)
         *   b) 'kfree' the memory
         */
        kobject_put(&dev->kobj);
-       edac_put_sysfs_subsys();
 }
 
 /* edac_dev -> instance information */
index 58aed67b7eba499c126a5d52cf3b26cd5497c2dc..1c79ae3e083a1d4dac885103c0c320f266b628a8 100644 (file)
@@ -1039,7 +1039,7 @@ int __init edac_mc_sysfs_init(void)
        mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
        if (!mci_pdev) {
                err = -ENOMEM;
-               goto out_put_sysfs;
+               goto out;
        }
 
        mci_pdev->bus = edac_subsys;
@@ -1057,8 +1057,6 @@ int __init edac_mc_sysfs_init(void)
 
  out_dev_free:
        kfree(mci_pdev);
- out_put_sysfs:
-       edac_put_sysfs_subsys();
  out:
        return err;
 }
@@ -1066,5 +1064,4 @@ int __init edac_mc_sysfs_init(void)
 void edac_mc_sysfs_exit(void)
 {
        device_unregister(mci_pdev);
-       edac_put_sysfs_subsys();
 }
index 9cb082a19d8a7ae2fbd7a2ae146bd3cd98a59618..059b5924988bf0b8743dc65cdbb0f231fc7188c8 100644 (file)
@@ -91,6 +91,39 @@ static void edac_workqueue_teardown(void)
        }
 }
 
+/*
+ * sysfs object: /sys/devices/system/edac
+ *     need to export to other files
+ */
+struct bus_type edac_subsys = {
+       .name = "edac",
+       .dev_name = "edac",
+};
+EXPORT_SYMBOL_GPL(edac_subsys);
+
+static int edac_subsys_init(void)
+{
+       int err;
+
+       /* create the /sys/devices/system/edac directory */
+       err = subsys_system_register(&edac_subsys, NULL);
+       if (err)
+               printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
+
+       return err;
+}
+
+static void edac_subsys_exit(void)
+{
+       bus_unregister(&edac_subsys);
+}
+
+/* return pointer to the 'edac' node in sysfs */
+struct bus_type *edac_get_sysfs_subsys(void)
+{
+       return &edac_subsys;
+}
+EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
 /*
  * edac_init
  *      module initialization entry point
@@ -101,6 +134,10 @@ static int __init edac_init(void)
 
        edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
 
+       err = edac_subsys_init();
+       if (err)
+               return err;
+
        /*
         * Harvest and clear any boot/initialization PCI parity errors
         *
@@ -129,6 +166,8 @@ err_wq:
        edac_mc_sysfs_exit();
 
 err_sysfs:
+       edac_subsys_exit();
+
        return err;
 }
 
@@ -144,6 +183,7 @@ static void __exit edac_exit(void)
        edac_workqueue_teardown();
        edac_mc_sysfs_exit();
        edac_debugfs_exit();
+       edac_subsys_exit();
 }
 
 /*
index 24d877f6e57751b07123771c2f9e7b898c17cee6..262f56cca9ffff2b925382ba8d0a069f694fbd5f 100644 (file)
@@ -364,7 +364,7 @@ static int edac_pci_main_kobj_setup(void)
        if (!try_module_get(THIS_MODULE)) {
                edac_dbg(1, "try_module_get() failed\n");
                err = -ENODEV;
-               goto mod_get_fail;
+               goto decrement_count_fail;
        }
 
        edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
@@ -399,9 +399,6 @@ kobject_init_and_add_fail:
 kzalloc_fail:
        module_put(THIS_MODULE);
 
-mod_get_fail:
-       edac_put_sysfs_subsys();
-
 decrement_count_fail:
        /* if are on this error exit, nothing to tear down */
        atomic_dec(&edac_pci_sysfs_refcount);
@@ -426,7 +423,6 @@ static void edac_pci_main_kobj_teardown(void)
        if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
                edac_dbg(0, "called kobject_put on main kobj\n");
                kobject_put(edac_pci_top_main_kobj);
-               edac_put_sysfs_subsys();
        }
 }
 
index ff07aae5b7fbd963b59a72e9fdfed2cc3ad721aa..952e411f01f2fc38d4d12426807491b4b5e4f2e8 100644 (file)
@@ -26,8 +26,6 @@ EXPORT_SYMBOL_GPL(edac_handlers);
 int edac_err_assert = 0;
 EXPORT_SYMBOL_GPL(edac_err_assert);
 
-static atomic_t edac_subsys_valid = ATOMIC_INIT(0);
-
 int edac_report_status = EDAC_REPORTING_ENABLED;
 EXPORT_SYMBOL_GPL(edac_report_status);
 
@@ -68,42 +66,3 @@ void edac_atomic_assert_error(void)
        edac_err_assert++;
 }
 EXPORT_SYMBOL_GPL(edac_atomic_assert_error);
-
-/*
- * sysfs object: /sys/devices/system/edac
- *     need to export to other files
- */
-struct bus_type edac_subsys = {
-       .name = "edac",
-       .dev_name = "edac",
-};
-EXPORT_SYMBOL_GPL(edac_subsys);
-
-/* return pointer to the 'edac' node in sysfs */
-struct bus_type *edac_get_sysfs_subsys(void)
-{
-       int err = 0;
-
-       if (atomic_read(&edac_subsys_valid))
-               goto out;
-
-       /* create the /sys/devices/system/edac directory */
-       err = subsys_system_register(&edac_subsys, NULL);
-       if (err) {
-               printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
-               return NULL;
-       }
-
-out:
-       atomic_inc(&edac_subsys_valid);
-       return &edac_subsys;
-}
-EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
-
-void edac_put_sysfs_subsys(void)
-{
-       /* last user unregisters it */
-       if (atomic_dec_and_test(&edac_subsys_valid))
-               bus_unregister(&edac_subsys);
-}
-EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys);
index da6964873dcf677d5fde0d5ddf68a7f27ed89419..98f915dfeeace78ef34be6148a838508e263dd51 100644 (file)
@@ -33,7 +33,6 @@ extern struct bus_type edac_subsys;
 extern int edac_handler_set(void);
 extern void edac_atomic_assert_error(void);
 extern struct bus_type *edac_get_sysfs_subsys(void);
-extern void edac_put_sysfs_subsys(void);
 
 enum {
        EDAC_REPORTING_ENABLED,