aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/memory.c')
-rw-r--r--drivers/base/memory.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 7ae413fdd5fc..8ce6de5a7e28 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -20,6 +20,7 @@
20#include <linux/kobject.h> 20#include <linux/kobject.h>
21#include <linux/memory_hotplug.h> 21#include <linux/memory_hotplug.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/mutex.h>
23#include <asm/atomic.h> 24#include <asm/atomic.h>
24#include <asm/uaccess.h> 25#include <asm/uaccess.h>
25 26
@@ -61,8 +62,8 @@ void unregister_memory_notifier(struct notifier_block *nb)
61/* 62/*
62 * register_memory - Setup a sysfs device for a memory block 63 * register_memory - Setup a sysfs device for a memory block
63 */ 64 */
64int register_memory(struct memory_block *memory, struct mem_section *section, 65static
65 struct node *root) 66int register_memory(struct memory_block *memory, struct mem_section *section)
66{ 67{
67 int error; 68 int error;
68 69
@@ -70,26 +71,18 @@ int register_memory(struct memory_block *memory, struct mem_section *section,
70 memory->sysdev.id = __section_nr(section); 71 memory->sysdev.id = __section_nr(section);
71 72
72 error = sysdev_register(&memory->sysdev); 73 error = sysdev_register(&memory->sysdev);
73
74 if (root && !error)
75 error = sysfs_create_link(&root->sysdev.kobj,
76 &memory->sysdev.kobj,
77 kobject_name(&memory->sysdev.kobj));
78
79 return error; 74 return error;
80} 75}
81 76
82static void 77static void
83unregister_memory(struct memory_block *memory, struct mem_section *section, 78unregister_memory(struct memory_block *memory, struct mem_section *section)
84 struct node *root)
85{ 79{
86 BUG_ON(memory->sysdev.cls != &memory_sysdev_class); 80 BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
87 BUG_ON(memory->sysdev.id != __section_nr(section)); 81 BUG_ON(memory->sysdev.id != __section_nr(section));
88 82
83 /* drop the ref. we got in remove_memory_block() */
84 kobject_put(&memory->sysdev.kobj);
89 sysdev_unregister(&memory->sysdev); 85 sysdev_unregister(&memory->sysdev);
90 if (root)
91 sysfs_remove_link(&root->sysdev.kobj,
92 kobject_name(&memory->sysdev.kobj));
93} 86}
94 87
95/* 88/*
@@ -193,7 +186,7 @@ memory_block_action(struct memory_block *mem, unsigned long action)
193 break; 186 break;
194 default: 187 default:
195 printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", 188 printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n",
196 __FUNCTION__, mem, action, action); 189 __func__, mem, action, action);
197 WARN_ON(1); 190 WARN_ON(1);
198 ret = -EINVAL; 191 ret = -EINVAL;
199 } 192 }
@@ -205,7 +198,7 @@ static int memory_block_change_state(struct memory_block *mem,
205 unsigned long to_state, unsigned long from_state_req) 198 unsigned long to_state, unsigned long from_state_req)
206{ 199{
207 int ret = 0; 200 int ret = 0;
208 down(&mem->state_sem); 201 mutex_lock(&mem->state_mutex);
209 202
210 if (mem->state != from_state_req) { 203 if (mem->state != from_state_req) {
211 ret = -EINVAL; 204 ret = -EINVAL;
@@ -217,7 +210,7 @@ static int memory_block_change_state(struct memory_block *mem,
217 mem->state = to_state; 210 mem->state = to_state;
218 211
219out: 212out:
220 up(&mem->state_sem); 213 mutex_unlock(&mem->state_mutex);
221 return ret; 214 return ret;
222} 215}
223 216
@@ -341,10 +334,10 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
341 334
342 mem->phys_index = __section_nr(section); 335 mem->phys_index = __section_nr(section);
343 mem->state = state; 336 mem->state = state;
344 init_MUTEX(&mem->state_sem); 337 mutex_init(&mem->state_mutex);
345 mem->phys_device = phys_device; 338 mem->phys_device = phys_device;
346 339
347 ret = register_memory(mem, section, NULL); 340 ret = register_memory(mem, section);
348 if (!ret) 341 if (!ret)
349 ret = mem_create_simple_file(mem, phys_index); 342 ret = mem_create_simple_file(mem, phys_index);
350 if (!ret) 343 if (!ret)
@@ -395,7 +388,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
395 mem_remove_simple_file(mem, phys_index); 388 mem_remove_simple_file(mem, phys_index);
396 mem_remove_simple_file(mem, state); 389 mem_remove_simple_file(mem, state);
397 mem_remove_simple_file(mem, phys_device); 390 mem_remove_simple_file(mem, phys_device);
398 unregister_memory(mem, section, NULL); 391 unregister_memory(mem, section);
399 392
400 return 0; 393 return 0;
401} 394}
@@ -451,6 +444,6 @@ int __init memory_dev_init(void)
451 ret = err; 444 ret = err;
452out: 445out:
453 if (ret) 446 if (ret)
454 printk(KERN_ERR "%s() failed: %d\n", __FUNCTION__, ret); 447 printk(KERN_ERR "%s() failed: %d\n", __func__, ret);
455 return ret; 448 return ret;
456} 449}