linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mempolicy: return NULL if node is NUMA_NO_NODE in get_task_policy
@ 2013-08-06  4:06 Jianguo Wu
  2013-08-06 21:03 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Jianguo Wu @ 2013-08-06  4:06 UTC (permalink / raw)
  To: Mel Gorman, Andrew Morton
  Cc: KOSAKI Motohiro, Rik van Riel, Hugh Dickins, linux-mm,
	linux-kernel, Hanjun Guo

If node == NUMA_NO_NODE, pol is NULL, we should return NULL instead of
do "if (!pol->mode)" check.

Signed-off-by: Jianguo Wu <wujianguo@huawei.com>
---
 mm/mempolicy.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 4baf12e..e0e3398 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -129,6 +129,8 @@ static struct mempolicy *get_task_policy(struct task_struct *p)
 		node = numa_node_id();
 		if (node != NUMA_NO_NODE)
 			pol = &preferred_node_policy[node];
+		else
+			return NULL;
 
 		/* preferred_node_policy is not initialised early in boot */
 		if (!pol->mode)
-- 
1.8.2.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mempolicy: return NULL if node is NUMA_NO_NODE in get_task_policy
  2013-08-06  4:06 [PATCH] mm/mempolicy: return NULL if node is NUMA_NO_NODE in get_task_policy Jianguo Wu
@ 2013-08-06 21:03 ` Andrew Morton
  2013-08-07  0:54   ` Jianguo Wu
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2013-08-06 21:03 UTC (permalink / raw)
  To: Jianguo Wu
  Cc: Mel Gorman, KOSAKI Motohiro, Rik van Riel, Hugh Dickins, linux-mm,
	linux-kernel, Hanjun Guo

On Tue, 6 Aug 2013 12:06:56 +0800 Jianguo Wu <wujianguo@huawei.com> wrote:

> If node == NUMA_NO_NODE, pol is NULL, we should return NULL instead of
> do "if (!pol->mode)" check.
> 
> Signed-off-by: Jianguo Wu <wujianguo@huawei.com>
> ---
>  mm/mempolicy.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 4baf12e..e0e3398 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -129,6 +129,8 @@ static struct mempolicy *get_task_policy(struct task_struct *p)
>  		node = numa_node_id();
>  		if (node != NUMA_NO_NODE)
>  			pol = &preferred_node_policy[node];
> +		else
> +			return NULL;
>  
>  		/* preferred_node_policy is not initialised early in boot */
>  		if (!pol->mode)

Well yes, it'll dereference a null pointer

This is neater, I think:

--- a/mm/mempolicy.c~mm-mempolicy-return-null-if-node-is-numa_no_node-in-get_task_policy
+++ a/mm/mempolicy.c
@@ -123,16 +123,19 @@ static struct mempolicy preferred_node_p
 static struct mempolicy *get_task_policy(struct task_struct *p)
 {
 	struct mempolicy *pol = p->mempolicy;
-	int node;
 
 	if (!pol) {
-		node = numa_node_id();
-		if (node != NUMA_NO_NODE)
-			pol = &preferred_node_policy[node];
+		int node = numa_node_id();
 
-		/* preferred_node_policy is not initialised early in boot */
-		if (!pol->mode)
-			pol = NULL;
+		if (node != NUMA_NO_NODE) {
+			pol = &preferred_node_policy[node];
+			/*
+			 * preferred_node_policy is not initialised early in
+			 * boot
+			 */
+			if (!pol->mode)
+				pol = NULL;
+		}
 	}
 
 	return pol;
_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mempolicy: return NULL if node is NUMA_NO_NODE in get_task_policy
  2013-08-06 21:03 ` Andrew Morton
@ 2013-08-07  0:54   ` Jianguo Wu
  0 siblings, 0 replies; 3+ messages in thread
From: Jianguo Wu @ 2013-08-07  0:54 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Mel Gorman, KOSAKI Motohiro, Rik van Riel, Hugh Dickins, linux-mm,
	linux-kernel, Hanjun Guo

Hi Andrew,

On 2013/8/7 5:03, Andrew Morton wrote:

> On Tue, 6 Aug 2013 12:06:56 +0800 Jianguo Wu <wujianguo@huawei.com> wrote:
> 
>> If node == NUMA_NO_NODE, pol is NULL, we should return NULL instead of
>> do "if (!pol->mode)" check.
>>
>> Signed-off-by: Jianguo Wu <wujianguo@huawei.com>
>> ---
>>  mm/mempolicy.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
>> index 4baf12e..e0e3398 100644
>> --- a/mm/mempolicy.c
>> +++ b/mm/mempolicy.c
>> @@ -129,6 +129,8 @@ static struct mempolicy *get_task_policy(struct task_struct *p)
>>  		node = numa_node_id();
>>  		if (node != NUMA_NO_NODE)
>>  			pol = &preferred_node_policy[node];
>> +		else
>> +			return NULL;
>>  
>>  		/* preferred_node_policy is not initialised early in boot */
>>  		if (!pol->mode)
> 
> Well yes, it'll dereference a null pointer
> 
> This is neater, I think:
> 

Yes, this is more readable, Thanks.

> --- a/mm/mempolicy.c~mm-mempolicy-return-null-if-node-is-numa_no_node-in-get_task_policy
> +++ a/mm/mempolicy.c
> @@ -123,16 +123,19 @@ static struct mempolicy preferred_node_p
>  static struct mempolicy *get_task_policy(struct task_struct *p)
>  {
>  	struct mempolicy *pol = p->mempolicy;
> -	int node;
>  
>  	if (!pol) {
> -		node = numa_node_id();
> -		if (node != NUMA_NO_NODE)
> -			pol = &preferred_node_policy[node];
> +		int node = numa_node_id();
>  
> -		/* preferred_node_policy is not initialised early in boot */
> -		if (!pol->mode)
> -			pol = NULL;
> +		if (node != NUMA_NO_NODE) {
> +			pol = &preferred_node_policy[node];
> +			/*
> +			 * preferred_node_policy is not initialised early in
> +			 * boot
> +			 */
> +			if (!pol->mode)
> +				pol = NULL;
> +		}
>  	}
>  
>  	return pol;
> _
> 
> 
> .
> 



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-07  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-06  4:06 [PATCH] mm/mempolicy: return NULL if node is NUMA_NO_NODE in get_task_policy Jianguo Wu
2013-08-06 21:03 ` Andrew Morton
2013-08-07  0:54   ` Jianguo Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).