aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/memory.c
diff options
context:
space:
mode:
authorBadari Pulavarty <pbadari@us.ibm.com>2008-02-11 12:23:18 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2008-04-19 22:10:19 -0400
commit00a41db522c77af33ea5ee9837d4f043ce150249 (patch)
tree97e145d00adadcaf00f7d0997b7089c8a7d53894 /drivers/base/memory.c
parentda19cbcf71cde3c09587b5924d113f0c7f1fd23a (diff)
driver core: register_memory/unregister_memory clean ups and bugfix
register_memory()/unregister_memory() never gets called with "root". unregister_memory() is accessing kobject_name of the object just freed up. Since no one uses the code, lets take the code out. And also, make register_memory() static. Another bug fix - before calling unregister_memory() remove_memory_block() gets a ref on kobject. unregister_memory() need to drop that ref before calling sysdev_unregister(). Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/memory.c')
-rw-r--r--drivers/base/memory.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 1f3801a8184..7891f7c9726 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -62,8 +62,8 @@ void unregister_memory_notifier(struct notifier_block *nb)
62/* 62/*
63 * register_memory - Setup a sysfs device for a memory block 63 * register_memory - Setup a sysfs device for a memory block
64 */ 64 */
65int register_memory(struct memory_block *memory, struct mem_section *section, 65static
66 struct node *root) 66int register_memory(struct memory_block *memory, struct mem_section *section)
67{ 67{
68 int error; 68 int error;
69 69
@@ -71,26 +71,18 @@ int register_memory(struct memory_block *memory, struct mem_section *section,
71 memory->sysdev.id = __section_nr(section); 71 memory->sysdev.id = __section_nr(section);
72 72
73 error = sysdev_register(&memory->sysdev); 73 error = sysdev_register(&memory->sysdev);
74
75 if (root && !error)
76 error = sysfs_create_link(&root->sysdev.kobj,
77 &memory->sysdev.kobj,
78 kobject_name(&memory->sysdev.kobj));
79
80 return error; 74 return error;
81} 75}
82 76
83static void 77static void
84unregister_memory(struct memory_block *memory, struct mem_section *section, 78unregister_memory(struct memory_block *memory, struct mem_section *section)
85 struct node *root)
86{ 79{
87 BUG_ON(memory->sysdev.cls != &memory_sysdev_class); 80 BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
88 BUG_ON(memory->sysdev.id != __section_nr(section)); 81 BUG_ON(memory->sysdev.id != __section_nr(section));
89 82
83 /* drop the ref. we got in remove_memory_block() */
84 kobject_put(&memory->sysdev.kobj);
90 sysdev_unregister(&memory->sysdev); 85 sysdev_unregister(&memory->sysdev);
91 if (root)
92 sysfs_remove_link(&root->sysdev.kobj,
93 kobject_name(&memory->sysdev.kobj));
94} 86}
95 87
96/* 88/*
@@ -345,7 +337,7 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
345 mutex_init(&mem->state_mutex); 337 mutex_init(&mem->state_mutex);
346 mem->phys_device = phys_device; 338 mem->phys_device = phys_device;
347 339
348 ret = register_memory(mem, section, NULL); 340 ret = register_memory(mem, section);
349 if (!ret) 341 if (!ret)
350 ret = mem_create_simple_file(mem, phys_index); 342 ret = mem_create_simple_file(mem, phys_index);
351 if (!ret) 343 if (!ret)
@@ -396,7 +388,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
396 mem_remove_simple_file(mem, phys_index); 388 mem_remove_simple_file(mem, phys_index);
397 mem_remove_simple_file(mem, state); 389 mem_remove_simple_file(mem, state);
398 mem_remove_simple_file(mem, phys_device); 390 mem_remove_simple_file(mem, phys_device);
399 unregister_memory(mem, section, NULL); 391 unregister_memory(mem, section);
400 392
401 return 0; 393 return 0;
402} 394}