Skip to content

Commit 733476c

Browse files
committed
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 <[email protected]>
1 parent fcd5c4d commit 733476c

File tree

6 files changed

+43
-56
lines changed

6 files changed

+43
-56
lines changed

drivers/edac/edac_device_sysfs.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
256256

257257
if (!try_module_get(edac_dev->owner)) {
258258
err = -ENODEV;
259-
goto err_mod_get;
259+
goto err_out;
260260
}
261261

262262
/* register */
@@ -282,9 +282,6 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
282282
err_kobj_reg:
283283
module_put(edac_dev->owner);
284284

285-
err_mod_get:
286-
edac_put_sysfs_subsys();
287-
288285
err_out:
289286
return err;
290287
}
@@ -306,7 +303,6 @@ void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev)
306303
* b) 'kfree' the memory
307304
*/
308305
kobject_put(&dev->kobj);
309-
edac_put_sysfs_subsys();
310306
}
311307

312308
/* edac_dev -> instance information */

drivers/edac/edac_mc_sysfs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ int __init edac_mc_sysfs_init(void)
10391039
mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
10401040
if (!mci_pdev) {
10411041
err = -ENOMEM;
1042-
goto out_put_sysfs;
1042+
goto out;
10431043
}
10441044

10451045
mci_pdev->bus = edac_subsys;
@@ -1057,14 +1057,11 @@ int __init edac_mc_sysfs_init(void)
10571057

10581058
out_dev_free:
10591059
kfree(mci_pdev);
1060-
out_put_sysfs:
1061-
edac_put_sysfs_subsys();
10621060
out:
10631061
return err;
10641062
}
10651063

10661064
void edac_mc_sysfs_exit(void)
10671065
{
10681066
device_unregister(mci_pdev);
1069-
edac_put_sysfs_subsys();
10701067
}

drivers/edac/edac_module.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,39 @@ static void edac_workqueue_teardown(void)
9191
}
9292
}
9393

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);
94127
/*
95128
* edac_init
96129
* module initialization entry point
@@ -101,6 +134,10 @@ static int __init edac_init(void)
101134

102135
edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
103136

137+
err = edac_subsys_init();
138+
if (err)
139+
return err;
140+
104141
/*
105142
* Harvest and clear any boot/initialization PCI parity errors
106143
*
@@ -129,6 +166,8 @@ static int __init edac_init(void)
129166
edac_mc_sysfs_exit();
130167

131168
err_sysfs:
169+
edac_subsys_exit();
170+
132171
return err;
133172
}
134173

@@ -144,6 +183,7 @@ static void __exit edac_exit(void)
144183
edac_workqueue_teardown();
145184
edac_mc_sysfs_exit();
146185
edac_debugfs_exit();
186+
edac_subsys_exit();
147187
}
148188

149189
/*

drivers/edac/edac_pci_sysfs.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static int edac_pci_main_kobj_setup(void)
364364
if (!try_module_get(THIS_MODULE)) {
365365
edac_dbg(1, "try_module_get() failed\n");
366366
err = -ENODEV;
367-
goto mod_get_fail;
367+
goto decrement_count_fail;
368368
}
369369

370370
edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
@@ -399,9 +399,6 @@ static int edac_pci_main_kobj_setup(void)
399399
kzalloc_fail:
400400
module_put(THIS_MODULE);
401401

402-
mod_get_fail:
403-
edac_put_sysfs_subsys();
404-
405402
decrement_count_fail:
406403
/* if are on this error exit, nothing to tear down */
407404
atomic_dec(&edac_pci_sysfs_refcount);
@@ -426,7 +423,6 @@ static void edac_pci_main_kobj_teardown(void)
426423
if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
427424
edac_dbg(0, "called kobject_put on main kobj\n");
428425
kobject_put(edac_pci_top_main_kobj);
429-
edac_put_sysfs_subsys();
430426
}
431427
}
432428

drivers/edac/edac_stub.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ EXPORT_SYMBOL_GPL(edac_handlers);
2626
int edac_err_assert = 0;
2727
EXPORT_SYMBOL_GPL(edac_err_assert);
2828

29-
static atomic_t edac_subsys_valid = ATOMIC_INIT(0);
30-
3129
int edac_report_status = EDAC_REPORTING_ENABLED;
3230
EXPORT_SYMBOL_GPL(edac_report_status);
3331

@@ -68,42 +66,3 @@ void edac_atomic_assert_error(void)
6866
edac_err_assert++;
6967
}
7068
EXPORT_SYMBOL_GPL(edac_atomic_assert_error);
71-
72-
/*
73-
* sysfs object: /sys/devices/system/edac
74-
* need to export to other files
75-
*/
76-
struct bus_type edac_subsys = {
77-
.name = "edac",
78-
.dev_name = "edac",
79-
};
80-
EXPORT_SYMBOL_GPL(edac_subsys);
81-
82-
/* return pointer to the 'edac' node in sysfs */
83-
struct bus_type *edac_get_sysfs_subsys(void)
84-
{
85-
int err = 0;
86-
87-
if (atomic_read(&edac_subsys_valid))
88-
goto out;
89-
90-
/* create the /sys/devices/system/edac directory */
91-
err = subsys_system_register(&edac_subsys, NULL);
92-
if (err) {
93-
printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
94-
return NULL;
95-
}
96-
97-
out:
98-
atomic_inc(&edac_subsys_valid);
99-
return &edac_subsys;
100-
}
101-
EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
102-
103-
void edac_put_sysfs_subsys(void)
104-
{
105-
/* last user unregisters it */
106-
if (atomic_dec_and_test(&edac_subsys_valid))
107-
bus_unregister(&edac_subsys);
108-
}
109-
EXPORT_SYMBOL_GPL(edac_put_sysfs_subsys);

include/linux/edac.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ extern struct bus_type edac_subsys;
3333
extern int edac_handler_set(void);
3434
extern void edac_atomic_assert_error(void);
3535
extern struct bus_type *edac_get_sysfs_subsys(void);
36-
extern void edac_put_sysfs_subsys(void);
3736

3837
enum {
3938
EDAC_REPORTING_ENABLED,

0 commit comments

Comments
 (0)