2012-10-31 07:04:05

by Wen Congyang

[permalink] [raw]
Subject: [PART2 Patch] some cleanups

From: Lai Jiangshan <[email protected]>

This patch is part2 of the following patchset:
https://lkml.org/lkml/2012/10/29/319

Part1 is here:
https://lkml.org/lkml/2012/10/31/30

This patch only does some cleanup, and no logic change. It can be applied
without the other parts.

Lai Jiangshan (1):
node: cleanup node_state_attr

drivers/base/node.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

--
1.8.0


2012-10-31 07:04:28

by Wen Congyang

[permalink] [raw]
Subject: [PART2 Patch] node: cleanup node_state_attr

From: Lai Jiangshan <[email protected]>

use [index] = init_value
use N_xxxxx instead of hardcode.

Make it more readability and easier to add new state.

Signed-off-by: Lai Jiangshan <[email protected]>
---
drivers/base/node.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index af1a177..5d7731e 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -614,23 +614,23 @@ static ssize_t show_node_state(struct device *dev,
{ __ATTR(name, 0444, show_node_state, NULL), state }

static struct node_attr node_state_attr[] = {
- _NODE_ATTR(possible, N_POSSIBLE),
- _NODE_ATTR(online, N_ONLINE),
- _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
- _NODE_ATTR(has_cpu, N_CPU),
+ [N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE),
+ [N_ONLINE] = _NODE_ATTR(online, N_ONLINE),
+ [N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
#ifdef CONFIG_HIGHMEM
- _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
+ [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
#endif
+ [N_CPU] = _NODE_ATTR(has_cpu, N_CPU),
};

static struct attribute *node_state_attrs[] = {
- &node_state_attr[0].attr.attr,
- &node_state_attr[1].attr.attr,
- &node_state_attr[2].attr.attr,
- &node_state_attr[3].attr.attr,
+ &node_state_attr[N_POSSIBLE].attr.attr,
+ &node_state_attr[N_ONLINE].attr.attr,
+ &node_state_attr[N_NORMAL_MEMORY].attr.attr,
#ifdef CONFIG_HIGHMEM
- &node_state_attr[4].attr.attr,
+ &node_state_attr[N_HIGH_MEMORY].attr.attr,
#endif
+ &node_state_attr[N_CPU].attr.attr,
NULL
};

--
1.8.0

2012-10-31 18:29:23

by David Rientjes

[permalink] [raw]
Subject: Re: [PART2 Patch] node: cleanup node_state_attr

On Wed, 31 Oct 2012, Wen Congyang wrote:

> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index af1a177..5d7731e 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -614,23 +614,23 @@ static ssize_t show_node_state(struct device *dev,
> { __ATTR(name, 0444, show_node_state, NULL), state }
>
> static struct node_attr node_state_attr[] = {
> - _NODE_ATTR(possible, N_POSSIBLE),
> - _NODE_ATTR(online, N_ONLINE),
> - _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
> - _NODE_ATTR(has_cpu, N_CPU),
> + [N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE),
> + [N_ONLINE] = _NODE_ATTR(online, N_ONLINE),
> + [N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
> #ifdef CONFIG_HIGHMEM
> - _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
> + [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
> #endif
> + [N_CPU] = _NODE_ATTR(has_cpu, N_CPU),
> };
>

Why change the index for N_CPU?

> static struct attribute *node_state_attrs[] = {
> - &node_state_attr[0].attr.attr,
> - &node_state_attr[1].attr.attr,
> - &node_state_attr[2].attr.attr,
> - &node_state_attr[3].attr.attr,
> + &node_state_attr[N_POSSIBLE].attr.attr,
> + &node_state_attr[N_ONLINE].attr.attr,
> + &node_state_attr[N_NORMAL_MEMORY].attr.attr,
> #ifdef CONFIG_HIGHMEM
> - &node_state_attr[4].attr.attr,
> + &node_state_attr[N_HIGH_MEMORY].attr.attr,
> #endif
> + &node_state_attr[N_CPU].attr.attr,
> NULL
> };
>

2012-11-01 05:46:18

by Wen Congyang

[permalink] [raw]
Subject: Re: [PART2 Patch] node: cleanup node_state_attr

At 11/01/2012 02:29 AM, David Rientjes Wrote:
> On Wed, 31 Oct 2012, Wen Congyang wrote:
>
>> diff --git a/drivers/base/node.c b/drivers/base/node.c
>> index af1a177..5d7731e 100644
>> --- a/drivers/base/node.c
>> +++ b/drivers/base/node.c
>> @@ -614,23 +614,23 @@ static ssize_t show_node_state(struct device *dev,
>> { __ATTR(name, 0444, show_node_state, NULL), state }
>>
>> static struct node_attr node_state_attr[] = {
>> - _NODE_ATTR(possible, N_POSSIBLE),
>> - _NODE_ATTR(online, N_ONLINE),
>> - _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
>> - _NODE_ATTR(has_cpu, N_CPU),
>> + [N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE),
>> + [N_ONLINE] = _NODE_ATTR(online, N_ONLINE),
>> + [N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
>> #ifdef CONFIG_HIGHMEM
>> - _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
>> + [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
>> #endif
>> + [N_CPU] = _NODE_ATTR(has_cpu, N_CPU),
>> };
>>
>
> Why change the index for N_CPU?

N_CPU > N_HIGH_MEMORY

We use this array to create attr file in sysfs. So changing the index for N_CPU
doesn't cause any other problem.

Thanks
Wen Congyang

>
>> static struct attribute *node_state_attrs[] = {
>> - &node_state_attr[0].attr.attr,
>> - &node_state_attr[1].attr.attr,
>> - &node_state_attr[2].attr.attr,
>> - &node_state_attr[3].attr.attr,
>> + &node_state_attr[N_POSSIBLE].attr.attr,
>> + &node_state_attr[N_ONLINE].attr.attr,
>> + &node_state_attr[N_NORMAL_MEMORY].attr.attr,
>> #ifdef CONFIG_HIGHMEM
>> - &node_state_attr[4].attr.attr,
>> + &node_state_attr[N_HIGH_MEMORY].attr.attr,
>> #endif
>> + &node_state_attr[N_CPU].attr.attr,
>> NULL
>> };
>>
>

2012-11-01 21:29:49

by David Rientjes

[permalink] [raw]
Subject: Re: [PART2 Patch] node: cleanup node_state_attr

On Thu, 1 Nov 2012, Wen Congyang wrote:

> >> diff --git a/drivers/base/node.c b/drivers/base/node.c
> >> index af1a177..5d7731e 100644
> >> --- a/drivers/base/node.c
> >> +++ b/drivers/base/node.c
> >> @@ -614,23 +614,23 @@ static ssize_t show_node_state(struct device *dev,
> >> { __ATTR(name, 0444, show_node_state, NULL), state }
> >>
> >> static struct node_attr node_state_attr[] = {
> >> - _NODE_ATTR(possible, N_POSSIBLE),
> >> - _NODE_ATTR(online, N_ONLINE),
> >> - _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
> >> - _NODE_ATTR(has_cpu, N_CPU),
> >> + [N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE),
> >> + [N_ONLINE] = _NODE_ATTR(online, N_ONLINE),
> >> + [N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
> >> #ifdef CONFIG_HIGHMEM
> >> - _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
> >> + [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
> >> #endif
> >> + [N_CPU] = _NODE_ATTR(has_cpu, N_CPU),
> >> };
> >>
> >
> > Why change the index for N_CPU?
>
> N_CPU > N_HIGH_MEMORY
>
> We use this array to create attr file in sysfs. So changing the index for N_CPU
> doesn't cause any other problem.
>

Acked-by: David Rientjes <[email protected]>