[PATCH] mm/sl[aou]b: make kfree() aware of error pointers

From: Jiri Kosina
Date: Tue Sep 09 2014 - 17:25:41 EST


kfree() is happy to accept NULL pointer and does nothing in such case.
It's reasonable to expect it to behave the same if ERR_PTR is passed to
it.

Inspired by a9cfcd63e8d ("ext4: avoid trying to kfree an ERR_PTR
pointer").

Signed-off-by: Jiri Kosina <jkosina@xxxxxxx>
---
mm/slab.c | 2 +-
mm/slob.c | 2 +-
mm/slub.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index a467b30..1a256ac 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3612,7 +3612,7 @@ void kfree(const void *objp)

trace_kfree(_RET_IP_, objp);

- if (unlikely(ZERO_OR_NULL_PTR(objp)))
+ if (unlikely(ZERO_OR_NULL_PTR(objp) || IS_ERR(objp)))
return;
local_irq_save(flags);
kfree_debugcheck(objp);
diff --git a/mm/slob.c b/mm/slob.c
index 21980e0..3abc42c 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -489,7 +489,7 @@ void kfree(const void *block)

trace_kfree(_RET_IP_, block);

- if (unlikely(ZERO_OR_NULL_PTR(block)))
+ if (unlikely(ZERO_OR_NULL_PTR(block) || IS_ERR(objp)))
return;
kmemleak_free(block);

diff --git a/mm/slub.c b/mm/slub.c
index 3e8afcc..46d18ce 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3338,7 +3338,7 @@ void kfree(const void *x)

trace_kfree(_RET_IP_, x);

- if (unlikely(ZERO_OR_NULL_PTR(x)))
+ if (unlikely(ZERO_OR_NULL_PTR(x) || IS_ERR(objp)))
return;

page = virt_to_head_page(x);

--
Jiri Kosina
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/