summaryrefslogtreecommitdiff
path: root/drivers/base/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/memory.c')
-rw-r--r--drivers/base/memory.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 3da6a43b7756..9f9b2359f718 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -48,7 +48,8 @@ static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj)
return MEMORY_CLASS_NAME;
}
-static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uevent_env *env)
+static int memory_uevent(struct kset *kset, struct kobject *obj,
+ struct kobj_uevent_env *env)
{
int retval = 0;
@@ -228,10 +229,11 @@ int memory_isolate_notify(unsigned long val, void *v)
* OK to have direct references to sparsemem variables in here.
*/
static int
-memory_section_action(unsigned long phys_index, unsigned long action)
+memory_block_action(unsigned long phys_index, unsigned long action)
{
int i;
unsigned long start_pfn, start_paddr;
+ unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
struct page *first_page;
int ret;
@@ -243,7 +245,7 @@ memory_section_action(unsigned long phys_index, unsigned long action)
* that way.
*/
if (action == MEM_ONLINE) {
- for (i = 0; i < PAGES_PER_SECTION; i++) {
+ for (i = 0; i < nr_pages; i++) {
if (PageReserved(first_page+i))
continue;
@@ -257,12 +259,12 @@ memory_section_action(unsigned long phys_index, unsigned long action)
switch (action) {
case MEM_ONLINE:
start_pfn = page_to_pfn(first_page);
- ret = online_pages(start_pfn, PAGES_PER_SECTION);
+ ret = online_pages(start_pfn, nr_pages);
break;
case MEM_OFFLINE:
start_paddr = page_to_pfn(first_page) << PAGE_SHIFT;
ret = remove_memory(start_paddr,
- PAGES_PER_SECTION << PAGE_SHIFT);
+ nr_pages << PAGE_SHIFT);
break;
default:
WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
@@ -276,7 +278,7 @@ memory_section_action(unsigned long phys_index, unsigned long action)
static int memory_block_change_state(struct memory_block *mem,
unsigned long to_state, unsigned long from_state_req)
{
- int i, ret = 0;
+ int ret = 0;
mutex_lock(&mem->state_mutex);
@@ -288,20 +290,11 @@ static int memory_block_change_state(struct memory_block *mem,
if (to_state == MEM_OFFLINE)
mem->state = MEM_GOING_OFFLINE;
- for (i = 0; i < sections_per_block; i++) {
- ret = memory_section_action(mem->start_section_nr + i,
- to_state);
- if (ret)
- break;
- }
-
- if (ret) {
- for (i = 0; i < sections_per_block; i++)
- memory_section_action(mem->start_section_nr + i,
- from_state_req);
+ ret = memory_block_action(mem->start_section_nr, to_state);
+ if (ret)
mem->state = from_state_req;
- } else
+ else
mem->state = to_state;
out:
@@ -396,15 +389,14 @@ memory_probe_store(struct class *class, struct class_attribute *attr,
ret = add_memory(nid, phys_addr,
PAGES_PER_SECTION << PAGE_SHIFT);
if (ret)
- break;
+ goto out;
phys_addr += MIN_MEMORY_BLOCK_SIZE;
}
- if (ret)
- count = ret;
-
- return count;
+ ret = count;
+out:
+ return ret;
}
static CLASS_ATTR(probe, S_IWUSR, NULL, memory_probe_store);