Introduce help macro to_memory_block to hide the conversion(device-->memory_block),
just clean up.
Signed-off-by: Gu Zheng <[email protected]>
---
drivers/base/memory.c | 27 ++++++++++++---------------
1 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 2b7813e..4a874c6 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -30,6 +30,8 @@ static DEFINE_MUTEX(mem_sysfs_mutex);
#define MEMORY_CLASS_NAME "memory"
+#define to_memory_block(dev) container_of(dev, struct memory_block, dev)
+
static int sections_per_block;
static inline int base_memory_block_id(int section_nr)
@@ -77,7 +79,7 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier);
static void memory_block_release(struct device *dev)
{
- struct memory_block *mem = container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
kfree(mem);
}
@@ -110,8 +112,7 @@ static unsigned long get_memory_block_size(void)
static ssize_t show_mem_start_phys_index(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
unsigned long phys_index;
phys_index = mem->start_section_nr / sections_per_block;
@@ -121,8 +122,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
static ssize_t show_mem_end_phys_index(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
unsigned long phys_index;
phys_index = mem->end_section_nr / sections_per_block;
@@ -137,8 +137,7 @@ static ssize_t show_mem_removable(struct device *dev,
{
unsigned long i, pfn;
int ret = 1;
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
for (i = 0; i < sections_per_block; i++) {
pfn = section_nr_to_pfn(mem->start_section_nr + i);
@@ -154,8 +153,7 @@ static ssize_t show_mem_removable(struct device *dev,
static ssize_t show_mem_state(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
ssize_t len = 0;
/*
@@ -280,7 +278,7 @@ static int __memory_block_change_state(struct memory_block *mem,
static int memory_subsys_online(struct device *dev)
{
- struct memory_block *mem = container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
int ret;
mutex_lock(&mem->state_mutex);
@@ -295,7 +293,7 @@ static int memory_subsys_online(struct device *dev)
static int memory_subsys_offline(struct device *dev)
{
- struct memory_block *mem = container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
int ret;
mutex_lock(&mem->state_mutex);
@@ -349,7 +347,7 @@ store_mem_state(struct device *dev,
bool offline;
int ret = -EINVAL;
- mem = container_of(dev, struct memory_block, dev);
+ mem = to_memory_block(dev);
lock_device_hotplug();
@@ -392,8 +390,7 @@ store_mem_state(struct device *dev,
static ssize_t show_phys_device(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
return sprintf(buf, "%d\n", mem->phys_device);
}
@@ -525,7 +522,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
put_device(&hint->dev);
if (!dev)
return NULL;
- return container_of(dev, struct memory_block, dev);
+ return to_memory_block(dev);
}
/*
--
1.7.7
(2013/08/26 19:32), Gu Zheng wrote:
> Introduce help macro to_memory_block to hide the conversion(device-->memory_block),
> just clean up.
>
> Signed-off-by: Gu Zheng <[email protected]>
> ---
It looks good to me.
Reviewed-by: Yasuaki Ishimatsu <[email protected]>
Thanks,
Yasuaki Ishimatsu
> drivers/base/memory.c | 27 ++++++++++++---------------
> 1 files changed, 12 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 2b7813e..4a874c6 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -30,6 +30,8 @@ static DEFINE_MUTEX(mem_sysfs_mutex);
>
> #define MEMORY_CLASS_NAME "memory"
>
> +#define to_memory_block(dev) container_of(dev, struct memory_block, dev)
> +
> static int sections_per_block;
>
> static inline int base_memory_block_id(int section_nr)
> @@ -77,7 +79,7 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier);
>
> static void memory_block_release(struct device *dev)
> {
> - struct memory_block *mem = container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
>
> kfree(mem);
> }
> @@ -110,8 +112,7 @@ static unsigned long get_memory_block_size(void)
> static ssize_t show_mem_start_phys_index(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> - struct memory_block *mem =
> - container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
> unsigned long phys_index;
>
> phys_index = mem->start_section_nr / sections_per_block;
> @@ -121,8 +122,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> static ssize_t show_mem_end_phys_index(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> - struct memory_block *mem =
> - container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
> unsigned long phys_index;
>
> phys_index = mem->end_section_nr / sections_per_block;
> @@ -137,8 +137,7 @@ static ssize_t show_mem_removable(struct device *dev,
> {
> unsigned long i, pfn;
> int ret = 1;
> - struct memory_block *mem =
> - container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
>
> for (i = 0; i < sections_per_block; i++) {
> pfn = section_nr_to_pfn(mem->start_section_nr + i);
> @@ -154,8 +153,7 @@ static ssize_t show_mem_removable(struct device *dev,
> static ssize_t show_mem_state(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> - struct memory_block *mem =
> - container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
> ssize_t len = 0;
>
> /*
> @@ -280,7 +278,7 @@ static int __memory_block_change_state(struct memory_block *mem,
>
> static int memory_subsys_online(struct device *dev)
> {
> - struct memory_block *mem = container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
> int ret;
>
> mutex_lock(&mem->state_mutex);
> @@ -295,7 +293,7 @@ static int memory_subsys_online(struct device *dev)
>
> static int memory_subsys_offline(struct device *dev)
> {
> - struct memory_block *mem = container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
> int ret;
>
> mutex_lock(&mem->state_mutex);
> @@ -349,7 +347,7 @@ store_mem_state(struct device *dev,
> bool offline;
> int ret = -EINVAL;
>
> - mem = container_of(dev, struct memory_block, dev);
> + mem = to_memory_block(dev);
>
> lock_device_hotplug();
>
> @@ -392,8 +390,7 @@ store_mem_state(struct device *dev,
> static ssize_t show_phys_device(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> - struct memory_block *mem =
> - container_of(dev, struct memory_block, dev);
> + struct memory_block *mem = to_memory_block(dev);
> return sprintf(buf, "%d\n", mem->phys_device);
> }
>
> @@ -525,7 +522,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
> put_device(&hint->dev);
> if (!dev)
> return NULL;
> - return container_of(dev, struct memory_block, dev);
> + return to_memory_block(dev);
> }
>
> /*
>
On Mon, Aug 26, 2013 at 06:32:50PM +0800, Gu Zheng wrote:
> Introduce help macro to_memory_block to hide the conversion(device-->memory_block),
> just clean up.
>
> Signed-off-by: Gu Zheng <[email protected]>
> ---
> drivers/base/memory.c | 27 ++++++++++++---------------
> 1 files changed, 12 insertions(+), 15 deletions(-)
This patch doesn't apply to my driver-core-next branch, as some changes
have happened in this area recently. Can you please refresh it and
resend it if it is still needed?
thanks,
greg k-h
Introduce help macro to_memory_block to hide the conversion(device-->memory_block),
just clean up.
Reviewed-by: Yasuaki Ishimatsu <[email protected]>
Signed-off-by: Gu Zheng <[email protected]>
---
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 2a38cd2..69e09a1 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -29,6 +29,8 @@ static DEFINE_MUTEX(mem_sysfs_mutex);
#define MEMORY_CLASS_NAME "memory"
+#define to_memory_block(dev) container_of(dev, struct memory_block, dev)
+
static int sections_per_block;
static inline int base_memory_block_id(int section_nr)
@@ -76,7 +78,7 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier);
static void memory_block_release(struct device *dev)
{
- struct memory_block *mem = container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
kfree(mem);
}
@@ -109,8 +111,7 @@ static unsigned long get_memory_block_size(void)
static ssize_t show_mem_start_phys_index(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
unsigned long phys_index;
phys_index = mem->start_section_nr / sections_per_block;
@@ -120,8 +121,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
static ssize_t show_mem_end_phys_index(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
unsigned long phys_index;
phys_index = mem->end_section_nr / sections_per_block;
@@ -136,8 +136,7 @@ static ssize_t show_mem_removable(struct device *dev,
{
unsigned long i, pfn;
int ret = 1;
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
for (i = 0; i < sections_per_block; i++) {
pfn = section_nr_to_pfn(mem->start_section_nr + i);
@@ -153,8 +152,7 @@ static ssize_t show_mem_removable(struct device *dev,
static ssize_t show_mem_state(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
ssize_t len = 0;
/*
@@ -282,7 +280,7 @@ static int memory_block_change_state(struct memory_block *mem,
/* The device lock serializes operations on memory_subsys_[online|offline] */
static int memory_subsys_online(struct device *dev)
{
- struct memory_block *mem = container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
int ret;
if (mem->state == MEM_ONLINE)
@@ -306,7 +304,7 @@ static int memory_subsys_online(struct device *dev)
static int memory_subsys_offline(struct device *dev)
{
- struct memory_block *mem = container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
if (mem->state == MEM_OFFLINE)
return 0;
@@ -318,11 +316,9 @@ static ssize_t
store_mem_state(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
- struct memory_block *mem;
+ struct memory_block *mem = to_memory_block(dev);
int ret, online_type;
- mem = container_of(dev, struct memory_block, dev);
-
lock_device_hotplug();
if (!strncmp(buf, "online_kernel", min_t(int, count, 13)))
@@ -376,8 +372,7 @@ store_mem_state(struct device *dev,
static ssize_t show_phys_device(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct memory_block *mem =
- container_of(dev, struct memory_block, dev);
+ struct memory_block *mem = to_memory_block(dev);
return sprintf(buf, "%d\n", mem->phys_device);
}
@@ -509,7 +504,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
put_device(&hint->dev);
if (!dev)
return NULL;
- return container_of(dev, struct memory_block, dev);
+ return to_memory_block(dev);
}
/*
--
1.7.7