diff options
Diffstat (limited to 'drivers/base/memory.c')
| -rw-r--r-- | drivers/base/memory.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 44e7de6ce694..86c88216a503 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
| @@ -275,13 +275,11 @@ memory_block_action(unsigned long phys_index, unsigned long action) | |||
| 275 | return ret; | 275 | return ret; |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | static int memory_block_change_state(struct memory_block *mem, | 278 | static int __memory_block_change_state(struct memory_block *mem, |
| 279 | unsigned long to_state, unsigned long from_state_req) | 279 | unsigned long to_state, unsigned long from_state_req) |
| 280 | { | 280 | { |
| 281 | int ret = 0; | 281 | int ret = 0; |
| 282 | 282 | ||
| 283 | mutex_lock(&mem->state_mutex); | ||
| 284 | |||
| 285 | if (mem->state != from_state_req) { | 283 | if (mem->state != from_state_req) { |
| 286 | ret = -EINVAL; | 284 | ret = -EINVAL; |
| 287 | goto out; | 285 | goto out; |
| @@ -309,10 +307,20 @@ static int memory_block_change_state(struct memory_block *mem, | |||
| 309 | break; | 307 | break; |
| 310 | } | 308 | } |
| 311 | out: | 309 | out: |
| 312 | mutex_unlock(&mem->state_mutex); | ||
| 313 | return ret; | 310 | return ret; |
| 314 | } | 311 | } |
| 315 | 312 | ||
| 313 | static int memory_block_change_state(struct memory_block *mem, | ||
| 314 | unsigned long to_state, unsigned long from_state_req) | ||
| 315 | { | ||
| 316 | int ret; | ||
| 317 | |||
| 318 | mutex_lock(&mem->state_mutex); | ||
| 319 | ret = __memory_block_change_state(mem, to_state, from_state_req); | ||
| 320 | mutex_unlock(&mem->state_mutex); | ||
| 321 | |||
| 322 | return ret; | ||
| 323 | } | ||
| 316 | static ssize_t | 324 | static ssize_t |
| 317 | store_mem_state(struct device *dev, | 325 | store_mem_state(struct device *dev, |
| 318 | struct device_attribute *attr, const char *buf, size_t count) | 326 | struct device_attribute *attr, const char *buf, size_t count) |
| @@ -653,6 +661,21 @@ int unregister_memory_section(struct mem_section *section) | |||
| 653 | } | 661 | } |
| 654 | 662 | ||
| 655 | /* | 663 | /* |
| 664 | * offline one memory block. If the memory block has been offlined, do nothing. | ||
| 665 | */ | ||
| 666 | int offline_memory_block(struct memory_block *mem) | ||
| 667 | { | ||
| 668 | int ret = 0; | ||
| 669 | |||
| 670 | mutex_lock(&mem->state_mutex); | ||
| 671 | if (mem->state != MEM_OFFLINE) | ||
| 672 | ret = __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); | ||
| 673 | mutex_unlock(&mem->state_mutex); | ||
| 674 | |||
| 675 | return ret; | ||
| 676 | } | ||
| 677 | |||
| 678 | /* | ||
| 656 | * Initialize the sysfs support for memory devices... | 679 | * Initialize the sysfs support for memory devices... |
| 657 | */ | 680 | */ |
| 658 | int __init memory_dev_init(void) | 681 | int __init memory_dev_init(void) |
