Skip to contentSkip to conversation

mm/mempolicy: return NULL if node is NUMA_NO_NODE in get_task_policy

PATCH In review Jianguo Wu 2 participants 3 messages Aug 6, 2013 – Aug 7, 2013

Subsystems (2)
lore
Share & tools
lore

Jianguo Wu

author
#0 lore raw

PATCH 1/1 mm/mempolicy: return NULL if node is NUMA_NO_NODE in get_task_policy

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

---
 mm/mempolicy.c | 2 ++
 1 file changed, 2 insertions(+)
mm/mempolicy.c +2 -0
index 4baf12e..e0e3398 100644
@@ -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)
Signature · 1 line
1.8.2.2
maintainer
#1 lore raw
Quoted 13 lines · On Tue, 6 Aug 2013 12:06:56 +0800 Jianguo Wu <[email protected]> wrote:

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

---
 mm/mempolicy.c | 2 ++
 1 file changed, 2 insertions(+)
mm/mempolicy.c +0 -0
index 4baf12e..e0e3398 100644

mm/mempolicy.c static struct mempolicy *get_task_policy(struct task_struct *p) · line 136

Quoted 8 lines
mm/mempolicy.c +2 -0
@@ -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:

mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-return-null-if-node-is-numa_no_node-in-get_task_policy +10 -7
@@ -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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#2 lore raw

Hi Andrew,

Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Tue, 6 Aug 2013 12:06:56 +0800 Jianguo Wu <[email protected]> wrote:

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

---
 mm/mempolicy.c | 2 ++
 1 file changed, 2 insertions(+)
mm/mempolicy.c +2 -0
index 4baf12e..e0e3398 100644
@@ -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;
 
Quoted 7 lines

mm/mempolicy.c static struct mempolicy *get_task_policy(struct task_struct *p) · line 136

Quoted 2 lines
mm/mempolicy.c +0 -0
 		/* 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.

Quoted 34 lines
mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-return-null-if-node-is-numa_no_node-in-get_task_policy +10 -7
@@ -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;

_

.