diff options
author | Borislav Petkov <borislav.petkov@amd.com> | 2010-09-02 11:26:48 -0400 |
---|---|---|
committer | Borislav Petkov <bp@amd64.org> | 2010-10-21 08:47:59 -0400 |
commit | 30e1f7a8122145f44f45c95366e27b6bb0b08428 (patch) | |
tree | ad1b549b88319b074505eed41914dd7b70f5434c /drivers/edac | |
parent | 7cfd4a87441f5ca3018fdd1f7ad67e8a73a05dc2 (diff) |
EDAC: Export edac sysfs class to users.
Move toplevel sysfs class to the stub and make it available to
non-modularized code too. Add proper refcounting of its users and move
the registration functionality into the reference counting routines.
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
Diffstat (limited to 'drivers/edac')
-rw-r--r-- | drivers/edac/edac_device_sysfs.c | 16 | ||||
-rw-r--r-- | drivers/edac/edac_mc_sysfs.c | 9 | ||||
-rw-r--r-- | drivers/edac/edac_module.c | 79 | ||||
-rw-r--r-- | drivers/edac/edac_module.h | 1 | ||||
-rw-r--r-- | drivers/edac/edac_pci_sysfs.c | 10 | ||||
-rw-r--r-- | drivers/edac/edac_stub.c | 51 |
6 files changed, 71 insertions, 95 deletions
diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c index 070968178a24..2941dca91aae 100644 --- a/drivers/edac/edac_device_sysfs.c +++ b/drivers/edac/edac_device_sysfs.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/ctype.h> | 13 | #include <linux/ctype.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/edac.h> | ||
16 | 17 | ||
17 | #include "edac_core.h" | 18 | #include "edac_core.h" |
18 | #include "edac_module.h" | 19 | #include "edac_module.h" |
@@ -235,7 +236,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) | |||
235 | debugf1("%s()\n", __func__); | 236 | debugf1("%s()\n", __func__); |
236 | 237 | ||
237 | /* get the /sys/devices/system/edac reference */ | 238 | /* get the /sys/devices/system/edac reference */ |
238 | edac_class = edac_get_edac_class(); | 239 | edac_class = edac_get_sysfs_class(); |
239 | if (edac_class == NULL) { | 240 | if (edac_class == NULL) { |
240 | debugf1("%s() no edac_class error\n", __func__); | 241 | debugf1("%s() no edac_class error\n", __func__); |
241 | err = -ENODEV; | 242 | err = -ENODEV; |
@@ -255,7 +256,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) | |||
255 | 256 | ||
256 | if (!try_module_get(edac_dev->owner)) { | 257 | if (!try_module_get(edac_dev->owner)) { |
257 | err = -ENODEV; | 258 | err = -ENODEV; |
258 | goto err_out; | 259 | goto err_mod_get; |
259 | } | 260 | } |
260 | 261 | ||
261 | /* register */ | 262 | /* register */ |
@@ -282,6 +283,9 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) | |||
282 | err_kobj_reg: | 283 | err_kobj_reg: |
283 | module_put(edac_dev->owner); | 284 | module_put(edac_dev->owner); |
284 | 285 | ||
286 | err_mod_get: | ||
287 | edac_put_sysfs_class(); | ||
288 | |||
285 | err_out: | 289 | err_out: |
286 | return err; | 290 | return err; |
287 | } | 291 | } |
@@ -290,12 +294,11 @@ err_out: | |||
290 | * edac_device_unregister_sysfs_main_kobj: | 294 | * edac_device_unregister_sysfs_main_kobj: |
291 | * the '..../edac/<name>' kobject | 295 | * the '..../edac/<name>' kobject |
292 | */ | 296 | */ |
293 | void edac_device_unregister_sysfs_main_kobj( | 297 | void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev) |
294 | struct edac_device_ctl_info *edac_dev) | ||
295 | { | 298 | { |
296 | debugf0("%s()\n", __func__); | 299 | debugf0("%s()\n", __func__); |
297 | debugf4("%s() name of kobject is: %s\n", | 300 | debugf4("%s() name of kobject is: %s\n", |
298 | __func__, kobject_name(&edac_dev->kobj)); | 301 | __func__, kobject_name(&dev->kobj)); |
299 | 302 | ||
300 | /* | 303 | /* |
301 | * Unregister the edac device's kobject and | 304 | * Unregister the edac device's kobject and |
@@ -304,7 +307,8 @@ void edac_device_unregister_sysfs_main_kobj( | |||
304 | * a) module_put() this module | 307 | * a) module_put() this module |
305 | * b) 'kfree' the memory | 308 | * b) 'kfree' the memory |
306 | */ | 309 | */ |
307 | kobject_put(&edac_dev->kobj); | 310 | kobject_put(&dev->kobj); |
311 | edac_put_sysfs_class(); | ||
308 | } | 312 | } |
309 | 313 | ||
310 | /* edac_dev -> instance information */ | 314 | /* edac_dev -> instance information */ |
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index aa93ad82ee07..a4135860149b 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include <linux/ctype.h> | 12 | #include <linux/ctype.h> |
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/edac.h> | ||
14 | #include <linux/bug.h> | 15 | #include <linux/bug.h> |
15 | 16 | ||
16 | #include "edac_core.h" | 17 | #include "edac_core.h" |
@@ -1017,7 +1018,7 @@ int edac_sysfs_setup_mc_kset(void) | |||
1017 | debugf1("%s()\n", __func__); | 1018 | debugf1("%s()\n", __func__); |
1018 | 1019 | ||
1019 | /* get the /sys/devices/system/edac class reference */ | 1020 | /* get the /sys/devices/system/edac class reference */ |
1020 | edac_class = edac_get_edac_class(); | 1021 | edac_class = edac_get_sysfs_class(); |
1021 | if (edac_class == NULL) { | 1022 | if (edac_class == NULL) { |
1022 | debugf1("%s() no edac_class error=%d\n", __func__, err); | 1023 | debugf1("%s() no edac_class error=%d\n", __func__, err); |
1023 | goto fail_out; | 1024 | goto fail_out; |
@@ -1028,15 +1029,16 @@ int edac_sysfs_setup_mc_kset(void) | |||
1028 | if (!mc_kset) { | 1029 | if (!mc_kset) { |
1029 | err = -ENOMEM; | 1030 | err = -ENOMEM; |
1030 | debugf1("%s() Failed to register '.../edac/mc'\n", __func__); | 1031 | debugf1("%s() Failed to register '.../edac/mc'\n", __func__); |
1031 | goto fail_out; | 1032 | goto fail_kset; |
1032 | } | 1033 | } |
1033 | 1034 | ||
1034 | debugf1("%s() Registered '.../edac/mc' kobject\n", __func__); | 1035 | debugf1("%s() Registered '.../edac/mc' kobject\n", __func__); |
1035 | 1036 | ||
1036 | return 0; | 1037 | return 0; |
1037 | 1038 | ||
1039 | fail_kset: | ||
1040 | edac_put_sysfs_class(); | ||
1038 | 1041 | ||
1039 | /* error unwind stack */ | ||
1040 | fail_out: | 1042 | fail_out: |
1041 | return err; | 1043 | return err; |
1042 | } | 1044 | } |
@@ -1049,5 +1051,6 @@ fail_out: | |||
1049 | void edac_sysfs_teardown_mc_kset(void) | 1051 | void edac_sysfs_teardown_mc_kset(void) |
1050 | { | 1052 | { |
1051 | kset_unregister(mc_kset); | 1053 | kset_unregister(mc_kset); |
1054 | edac_put_sysfs_class(); | ||
1052 | } | 1055 | } |
1053 | 1056 | ||
diff --git a/drivers/edac/edac_module.c b/drivers/edac/edac_module.c index 7e1374afd967..be4b075c3098 100644 --- a/drivers/edac/edac_module.c +++ b/drivers/edac/edac_module.c | |||
@@ -27,15 +27,6 @@ EXPORT_SYMBOL_GPL(edac_debug_level); | |||
27 | struct workqueue_struct *edac_workqueue; | 27 | struct workqueue_struct *edac_workqueue; |
28 | 28 | ||
29 | /* | 29 | /* |
30 | * sysfs object: /sys/devices/system/edac | ||
31 | * need to export to other files in this modules | ||
32 | */ | ||
33 | static struct sysdev_class edac_class = { | ||
34 | .name = "edac", | ||
35 | }; | ||
36 | static int edac_class_valid; | ||
37 | |||
38 | /* | ||
39 | * edac_op_state_to_string() | 30 | * edac_op_state_to_string() |
40 | */ | 31 | */ |
41 | char *edac_op_state_to_string(int opstate) | 32 | char *edac_op_state_to_string(int opstate) |
@@ -55,60 +46,6 @@ char *edac_op_state_to_string(int opstate) | |||
55 | } | 46 | } |
56 | 47 | ||
57 | /* | 48 | /* |
58 | * edac_get_edac_class() | ||
59 | * | ||
60 | * return pointer to the edac class of 'edac' | ||
61 | */ | ||
62 | struct sysdev_class *edac_get_edac_class(void) | ||
63 | { | ||
64 | struct sysdev_class *classptr = NULL; | ||
65 | |||
66 | if (edac_class_valid) | ||
67 | classptr = &edac_class; | ||
68 | |||
69 | return classptr; | ||
70 | } | ||
71 | |||
72 | /* | ||
73 | * edac_register_sysfs_edac_name() | ||
74 | * | ||
75 | * register the 'edac' into /sys/devices/system | ||
76 | * | ||
77 | * return: | ||
78 | * 0 success | ||
79 | * !0 error | ||
80 | */ | ||
81 | static int edac_register_sysfs_edac_name(void) | ||
82 | { | ||
83 | int err; | ||
84 | |||
85 | /* create the /sys/devices/system/edac directory */ | ||
86 | err = sysdev_class_register(&edac_class); | ||
87 | |||
88 | if (err) { | ||
89 | debugf1("%s() error=%d\n", __func__, err); | ||
90 | return err; | ||
91 | } | ||
92 | |||
93 | edac_class_valid = 1; | ||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * sysdev_class_unregister() | ||
99 | * | ||
100 | * unregister the 'edac' from /sys/devices/system | ||
101 | */ | ||
102 | static void edac_unregister_sysfs_edac_name(void) | ||
103 | { | ||
104 | /* only if currently registered, then unregister it */ | ||
105 | if (edac_class_valid) | ||
106 | sysdev_class_unregister(&edac_class); | ||
107 | |||
108 | edac_class_valid = 0; | ||
109 | } | ||
110 | |||
111 | /* | ||
112 | * edac_workqueue_setup | 49 | * edac_workqueue_setup |
113 | * initialize the edac work queue for polling operations | 50 | * initialize the edac work queue for polling operations |
114 | */ | 51 | */ |
@@ -154,21 +91,11 @@ static int __init edac_init(void) | |||
154 | edac_pci_clear_parity_errors(); | 91 | edac_pci_clear_parity_errors(); |
155 | 92 | ||
156 | /* | 93 | /* |
157 | * perform the registration of the /sys/devices/system/edac class object | ||
158 | */ | ||
159 | if (edac_register_sysfs_edac_name()) { | ||
160 | edac_printk(KERN_ERR, EDAC_MC, | ||
161 | "Error initializing 'edac' kobject\n"); | ||
162 | err = -ENODEV; | ||
163 | goto error; | ||
164 | } | ||
165 | |||
166 | /* | ||
167 | * now set up the mc_kset under the edac class object | 94 | * now set up the mc_kset under the edac class object |
168 | */ | 95 | */ |
169 | err = edac_sysfs_setup_mc_kset(); | 96 | err = edac_sysfs_setup_mc_kset(); |
170 | if (err) | 97 | if (err) |
171 | goto sysfs_setup_fail; | 98 | goto error; |
172 | 99 | ||
173 | /* Setup/Initialize the workq for this core */ | 100 | /* Setup/Initialize the workq for this core */ |
174 | err = edac_workqueue_setup(); | 101 | err = edac_workqueue_setup(); |
@@ -183,9 +110,6 @@ static int __init edac_init(void) | |||
183 | workq_fail: | 110 | workq_fail: |
184 | edac_sysfs_teardown_mc_kset(); | 111 | edac_sysfs_teardown_mc_kset(); |
185 | 112 | ||
186 | sysfs_setup_fail: | ||
187 | edac_unregister_sysfs_edac_name(); | ||
188 | |||
189 | error: | 113 | error: |
190 | return err; | 114 | return err; |
191 | } | 115 | } |
@@ -201,7 +125,6 @@ static void __exit edac_exit(void) | |||
201 | /* tear down the various subsystems */ | 125 | /* tear down the various subsystems */ |
202 | edac_workqueue_teardown(); | 126 | edac_workqueue_teardown(); |
203 | edac_sysfs_teardown_mc_kset(); | 127 | edac_sysfs_teardown_mc_kset(); |
204 | edac_unregister_sysfs_edac_name(); | ||
205 | } | 128 | } |
206 | 129 | ||
207 | /* | 130 | /* |
diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h index 233d4798c3aa..17aabb7b90ec 100644 --- a/drivers/edac/edac_module.h +++ b/drivers/edac/edac_module.h | |||
@@ -42,7 +42,6 @@ extern void edac_device_unregister_sysfs_main_kobj( | |||
42 | struct edac_device_ctl_info *edac_dev); | 42 | struct edac_device_ctl_info *edac_dev); |
43 | extern int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev); | 43 | extern int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev); |
44 | extern void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev); | 44 | extern void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev); |
45 | extern struct sysdev_class *edac_get_edac_class(void); | ||
46 | 45 | ||
47 | /* edac core workqueue: single CPU mode */ | 46 | /* edac core workqueue: single CPU mode */ |
48 | extern struct workqueue_struct *edac_workqueue; | 47 | extern struct workqueue_struct *edac_workqueue; |
diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c index c39697df9cb4..023b01cb5175 100644 --- a/drivers/edac/edac_pci_sysfs.c +++ b/drivers/edac/edac_pci_sysfs.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * | 7 | * |
8 | */ | 8 | */ |
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/sysdev.h> | 10 | #include <linux/edac.h> |
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/ctype.h> | 12 | #include <linux/ctype.h> |
13 | 13 | ||
@@ -354,7 +354,7 @@ static int edac_pci_main_kobj_setup(void) | |||
354 | /* First time, so create the main kobject and its | 354 | /* First time, so create the main kobject and its |
355 | * controls and atributes | 355 | * controls and atributes |
356 | */ | 356 | */ |
357 | edac_class = edac_get_edac_class(); | 357 | edac_class = edac_get_sysfs_class(); |
358 | if (edac_class == NULL) { | 358 | if (edac_class == NULL) { |
359 | debugf1("%s() no edac_class\n", __func__); | 359 | debugf1("%s() no edac_class\n", __func__); |
360 | err = -ENODEV; | 360 | err = -ENODEV; |
@@ -368,7 +368,7 @@ static int edac_pci_main_kobj_setup(void) | |||
368 | if (!try_module_get(THIS_MODULE)) { | 368 | if (!try_module_get(THIS_MODULE)) { |
369 | debugf1("%s() try_module_get() failed\n", __func__); | 369 | debugf1("%s() try_module_get() failed\n", __func__); |
370 | err = -ENODEV; | 370 | err = -ENODEV; |
371 | goto decrement_count_fail; | 371 | goto mod_get_fail; |
372 | } | 372 | } |
373 | 373 | ||
374 | edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); | 374 | edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); |
@@ -403,6 +403,9 @@ kobject_init_and_add_fail: | |||
403 | kzalloc_fail: | 403 | kzalloc_fail: |
404 | module_put(THIS_MODULE); | 404 | module_put(THIS_MODULE); |
405 | 405 | ||
406 | mod_get_fail: | ||
407 | edac_put_sysfs_class(); | ||
408 | |||
406 | decrement_count_fail: | 409 | decrement_count_fail: |
407 | /* if are on this error exit, nothing to tear down */ | 410 | /* if are on this error exit, nothing to tear down */ |
408 | atomic_dec(&edac_pci_sysfs_refcount); | 411 | atomic_dec(&edac_pci_sysfs_refcount); |
@@ -429,6 +432,7 @@ static void edac_pci_main_kobj_teardown(void) | |||
429 | __func__); | 432 | __func__); |
430 | kobject_put(edac_pci_top_main_kobj); | 433 | kobject_put(edac_pci_top_main_kobj); |
431 | } | 434 | } |
435 | edac_put_sysfs_class(); | ||
432 | } | 436 | } |
433 | 437 | ||
434 | /* | 438 | /* |
diff --git a/drivers/edac/edac_stub.c b/drivers/edac/edac_stub.c index 20b428aa155e..aab970760b75 100644 --- a/drivers/edac/edac_stub.c +++ b/drivers/edac/edac_stub.c | |||
@@ -3,10 +3,13 @@ | |||
3 | * | 3 | * |
4 | * Author: Dave Jiang <djiang@mvista.com> | 4 | * Author: Dave Jiang <djiang@mvista.com> |
5 | * | 5 | * |
6 | * 2007 (c) MontaVista Software, Inc. This file is licensed under | 6 | * 2007 (c) MontaVista Software, Inc. |
7 | * the terms of the GNU General Public License version 2. This program | 7 | * 2010 (c) Advanced Micro Devices Inc. |
8 | * is licensed "as is" without any warranty of any kind, whether express | 8 | * Borislav Petkov <borislav.petkov@amd.com> |
9 | * or implied. | 9 | * |
10 | * This file is licensed under the terms of the GNU General Public | ||
11 | * License version 2. This program is licensed "as is" without any | ||
12 | * warranty of any kind, whether express or implied. | ||
10 | * | 13 | * |
11 | */ | 14 | */ |
12 | #include <linux/module.h> | 15 | #include <linux/module.h> |
@@ -23,6 +26,8 @@ EXPORT_SYMBOL_GPL(edac_handlers); | |||
23 | int edac_err_assert = 0; | 26 | int edac_err_assert = 0; |
24 | EXPORT_SYMBOL_GPL(edac_err_assert); | 27 | EXPORT_SYMBOL_GPL(edac_err_assert); |
25 | 28 | ||
29 | static atomic_t edac_class_valid = ATOMIC_INIT(0); | ||
30 | |||
26 | /* | 31 | /* |
27 | * called to determine if there is an EDAC driver interested in | 32 | * called to determine if there is an EDAC driver interested in |
28 | * knowing an event (such as NMI) occurred | 33 | * knowing an event (such as NMI) occurred |
@@ -44,3 +49,41 @@ void edac_atomic_assert_error(void) | |||
44 | edac_err_assert++; | 49 | edac_err_assert++; |
45 | } | 50 | } |
46 | EXPORT_SYMBOL_GPL(edac_atomic_assert_error); | 51 | EXPORT_SYMBOL_GPL(edac_atomic_assert_error); |
52 | |||
53 | /* | ||
54 | * sysfs object: /sys/devices/system/edac | ||
55 | * need to export to other files | ||
56 | */ | ||
57 | struct sysdev_class edac_class = { | ||
58 | .name = "edac", | ||
59 | }; | ||
60 | EXPORT_SYMBOL_GPL(edac_class); | ||
61 | |||
62 | /* return pointer to the 'edac' node in sysfs */ | ||
63 | struct sysdev_class *edac_get_sysfs_class(void) | ||
64 | { | ||
65 | int err = 0; | ||
66 | |||
67 | if (atomic_read(&edac_class_valid)) | ||
68 | goto out; | ||
69 | |||
70 | /* create the /sys/devices/system/edac directory */ | ||
71 | err = sysdev_class_register(&edac_class); | ||
72 | if (err) { | ||
73 | printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n"); | ||
74 | return NULL; | ||
75 | } | ||
76 | |||
77 | out: | ||
78 | atomic_inc(&edac_class_valid); | ||
79 | return &edac_class; | ||
80 | } | ||
81 | EXPORT_SYMBOL_GPL(edac_get_sysfs_class); | ||
82 | |||
83 | void edac_put_sysfs_class(void) | ||
84 | { | ||
85 | /* last user unregisters it */ | ||
86 | if (atomic_dec_and_test(&edac_class_valid)) | ||
87 | sysdev_class_unregister(&edac_class); | ||
88 | } | ||
89 | EXPORT_SYMBOL_GPL(edac_put_sysfs_class); | ||