Skip to contentSkip to conversation

Fix to return wrong pointer in slob

PATCH Applied MinChan Kim 4 participants 4 messages May 19, 2008 – May 20, 2008 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix to return wrong pointer in slob

Although slob_alloc return NULL, __kmalloc_node returns NULL + align. Because align always can be changed, it is very hard for debugging problem of no page if it don't return NULL.

We have to return NULL in case of no page.

---
 mm/slob.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
mm/slob.c +6 -3
index 6038cba..258d76d 100644
@@ -469,9 +469,12 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
 			return ZERO_SIZE_PTR;
 
 		m = slob_alloc(size + align, gfp, align, node);
-		if (m)
-			*m = size;
-		return (void *)m + align;
+		if (!m)
+			return NULL;
+		else {
+			*m = size; 
+			return (void *)m + align;
+		}
 	} else {
 		void *ret;
 
Signature · 7 lines
1.5.4.3

--
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>
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · MinChan Kim

Although slob_alloc return NULL, __kmalloc_node returns NULL + align. Because align always can be changed, it is very hard for debugging problem of no page if it don't return NULL.

We have to return NULL in case of no page.

---
 mm/slob.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
mm/slob.c +0 -0
index 6038cba..258d76d 100644
@@ -469,9 +469,12 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
 			return ZERO_SIZE_PTR;
 

mm/slob.c void *__kmalloc_node(size_t size, gfp_t gfp, int node) · line 477

Quoted 10 lines
mm/slob.c +6 -3
 		m = slob_alloc(size + align, gfp, align, node);
-		if (m)
-			*m = size;
-		return (void *)m + align;
+		if (!m)
+			return NULL;
+		else {
+			*m = size; 
+			return (void *)m + align;
+		}

This looks good, but I would remove the 'else {' and '}' here. It's nice to have the 'normal path' minimally indented.

Otherwise,

[cc:ed to Pekka, who manages the allocator tree]

Quoted 3 lines
mm/slob.c +0 -0
 	} else {
 		void *ret;
 
Signature · 7 lines
Mathematics is the supreme nostalgia of our time.

--
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>
Applied
#2 lore raw
Quoted 8 lines · Matt Mackall

This looks good, but I would remove the 'else {' and '}' here. It's nice to have the 'normal path' minimally indented.

Otherwise,

[cc:ed to Pekka, who manages the allocator tree]

Applied, thanks!

--
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>

#3 lore raw
In reply to Matt Mackall
Quoted 20 lines · Matt Mackall
Quoted 18 lines · MinChan Kim

Although slob_alloc return NULL, __kmalloc_node returns NULL + align. Because align always can be changed, it is very hard for debugging problem of no page if it don't return NULL.

We have to return NULL in case of no page.

---
 mm/slob.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
mm/slob.c +0 -0
index 6038cba..258d76d 100644
@@ -469,9 +469,12 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
                      return ZERO_SIZE_PTR;
 
Quoted 13 lines

mm/slob.c void *__kmalloc_node(size_t size, gfp_t gfp, int node) · line 477

Quoted 10 lines
mm/slob.c +6 -3
              m = slob_alloc(size + align, gfp, align, node);
-             if (m)
-                     *m = size;
-             return (void *)m + align;
+             if (!m)
+                     return NULL;
+             else {
+                     *m = size;
+                     return (void *)m + align;
+             }

This looks good, but I would remove the 'else {' and '}' here. It's nice to have the 'normal path' minimally indented.

I agree
Thanks, Matt :)

Signature · 8 lines
Thanks,
MinChan Kim

--
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>