diff options
author | Gu Zheng <guz.fnst@cn.fujitsu.com> | 2013-08-28 02:38:27 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-28 18:47:38 -0400 |
commit | 7315f0ccfc283ae998ca4d8102de83bba21936fa (patch) | |
tree | 7eb979ea97f74792da676b47bc59dd21c9ce66f3 /drivers/base | |
parent | bd8c154a62d47b0ec2abf87e35dccf081781d81c (diff) |
drivers/base/memory.c: introduce help macro to_memory_block
Introduce help macro to_memory_block to hide the conversion(device-->memory_block),
just clean up.
Reviewed-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/memory.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 2a38cd2da2e5..69e09a1b62a4 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -29,6 +29,8 @@ static DEFINE_MUTEX(mem_sysfs_mutex); | |||
29 | 29 | ||
30 | #define MEMORY_CLASS_NAME "memory" | 30 | #define MEMORY_CLASS_NAME "memory" |
31 | 31 | ||
32 | #define to_memory_block(dev) container_of(dev, struct memory_block, dev) | ||
33 | |||
32 | static int sections_per_block; | 34 | static int sections_per_block; |
33 | 35 | ||
34 | static inline int base_memory_block_id(int section_nr) | 36 | static inline int base_memory_block_id(int section_nr) |
@@ -76,7 +78,7 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier); | |||
76 | 78 | ||
77 | static void memory_block_release(struct device *dev) | 79 | static void memory_block_release(struct device *dev) |
78 | { | 80 | { |
79 | struct memory_block *mem = container_of(dev, struct memory_block, dev); | 81 | struct memory_block *mem = to_memory_block(dev); |
80 | 82 | ||
81 | kfree(mem); | 83 | kfree(mem); |
82 | } | 84 | } |
@@ -109,8 +111,7 @@ static unsigned long get_memory_block_size(void) | |||
109 | static ssize_t show_mem_start_phys_index(struct device *dev, | 111 | static ssize_t show_mem_start_phys_index(struct device *dev, |
110 | struct device_attribute *attr, char *buf) | 112 | struct device_attribute *attr, char *buf) |
111 | { | 113 | { |
112 | struct memory_block *mem = | 114 | struct memory_block *mem = to_memory_block(dev); |
113 | container_of(dev, struct memory_block, dev); | ||
114 | unsigned long phys_index; | 115 | unsigned long phys_index; |
115 | 116 | ||
116 | phys_index = mem->start_section_nr / sections_per_block; | 117 | phys_index = mem->start_section_nr / sections_per_block; |
@@ -120,8 +121,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev, | |||
120 | static ssize_t show_mem_end_phys_index(struct device *dev, | 121 | static ssize_t show_mem_end_phys_index(struct device *dev, |
121 | struct device_attribute *attr, char *buf) | 122 | struct device_attribute *attr, char *buf) |
122 | { | 123 | { |
123 | struct memory_block *mem = | 124 | struct memory_block *mem = to_memory_block(dev); |
124 | container_of(dev, struct memory_block, dev); | ||
125 | unsigned long phys_index; | 125 | unsigned long phys_index; |
126 | 126 | ||
127 | phys_index = mem->end_section_nr / sections_per_block; | 127 | phys_index = mem->end_section_nr / sections_per_block; |
@@ -136,8 +136,7 @@ static ssize_t show_mem_removable(struct device *dev, | |||
136 | { | 136 | { |
137 | unsigned long i, pfn; | 137 | unsigned long i, pfn; |
138 | int ret = 1; | 138 | int ret = 1; |
139 | struct memory_block *mem = | 139 | struct memory_block *mem = to_memory_block(dev); |
140 | container_of(dev, struct memory_block, dev); | ||
141 | 140 | ||
142 | for (i = 0; i < sections_per_block; i++) { | 141 | for (i = 0; i < sections_per_block; i++) { |
143 | pfn = section_nr_to_pfn(mem->start_section_nr + i); | 142 | pfn = section_nr_to_pfn(mem->start_section_nr + i); |
@@ -153,8 +152,7 @@ static ssize_t show_mem_removable(struct device *dev, | |||
153 | static ssize_t show_mem_state(struct device *dev, | 152 | static ssize_t show_mem_state(struct device *dev, |
154 | struct device_attribute *attr, char *buf) | 153 | struct device_attribute *attr, char *buf) |
155 | { | 154 | { |
156 | struct memory_block *mem = | 155 | struct memory_block *mem = to_memory_block(dev); |
157 | container_of(dev, struct memory_block, dev); | ||
158 | ssize_t len = 0; | 156 | ssize_t len = 0; |
159 | 157 | ||
160 | /* | 158 | /* |
@@ -282,7 +280,7 @@ static int memory_block_change_state(struct memory_block *mem, | |||
282 | /* The device lock serializes operations on memory_subsys_[online|offline] */ | 280 | /* The device lock serializes operations on memory_subsys_[online|offline] */ |
283 | static int memory_subsys_online(struct device *dev) | 281 | static int memory_subsys_online(struct device *dev) |
284 | { | 282 | { |
285 | struct memory_block *mem = container_of(dev, struct memory_block, dev); | 283 | struct memory_block *mem = to_memory_block(dev); |
286 | int ret; | 284 | int ret; |
287 | 285 | ||
288 | if (mem->state == MEM_ONLINE) | 286 | if (mem->state == MEM_ONLINE) |
@@ -306,7 +304,7 @@ static int memory_subsys_online(struct device *dev) | |||
306 | 304 | ||
307 | static int memory_subsys_offline(struct device *dev) | 305 | static int memory_subsys_offline(struct device *dev) |
308 | { | 306 | { |
309 | struct memory_block *mem = container_of(dev, struct memory_block, dev); | 307 | struct memory_block *mem = to_memory_block(dev); |
310 | 308 | ||
311 | if (mem->state == MEM_OFFLINE) | 309 | if (mem->state == MEM_OFFLINE) |
312 | return 0; | 310 | return 0; |
@@ -318,11 +316,9 @@ static ssize_t | |||
318 | store_mem_state(struct device *dev, | 316 | store_mem_state(struct device *dev, |
319 | struct device_attribute *attr, const char *buf, size_t count) | 317 | struct device_attribute *attr, const char *buf, size_t count) |
320 | { | 318 | { |
321 | struct memory_block *mem; | 319 | struct memory_block *mem = to_memory_block(dev); |
322 | int ret, online_type; | 320 | int ret, online_type; |
323 | 321 | ||
324 | mem = container_of(dev, struct memory_block, dev); | ||
325 | |||
326 | lock_device_hotplug(); | 322 | lock_device_hotplug(); |
327 | 323 | ||
328 | if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) | 324 | if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) |
@@ -376,8 +372,7 @@ store_mem_state(struct device *dev, | |||
376 | static ssize_t show_phys_device(struct device *dev, | 372 | static ssize_t show_phys_device(struct device *dev, |
377 | struct device_attribute *attr, char *buf) | 373 | struct device_attribute *attr, char *buf) |
378 | { | 374 | { |
379 | struct memory_block *mem = | 375 | struct memory_block *mem = to_memory_block(dev); |
380 | container_of(dev, struct memory_block, dev); | ||
381 | return sprintf(buf, "%d\n", mem->phys_device); | 376 | return sprintf(buf, "%d\n", mem->phys_device); |
382 | } | 377 | } |
383 | 378 | ||
@@ -509,7 +504,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section, | |||
509 | put_device(&hint->dev); | 504 | put_device(&hint->dev); |
510 | if (!dev) | 505 | if (!dev) |
511 | return NULL; | 506 | return NULL; |
512 | return container_of(dev, struct memory_block, dev); | 507 | return to_memory_block(dev); |
513 | } | 508 | } |
514 | 509 | ||
515 | /* | 510 | /* |