linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/sl[aou]b: make kfree() aware of error pointers
@ 2014-09-09 21:25 Jiri Kosina
  2014-09-09 23:21 ` Andrew Morton
  0 siblings, 1 reply; 22+ messages in thread
From: Jiri Kosina @ 2014-09-09 21:25 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton
  Cc: linux-kernel, linux-mm, Dan Carpenter, Theodore Ts'o

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@suse.cz>
---
 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, 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] 22+ messages in thread

end of thread, other threads:[~2014-09-11 14:15 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-09 21:25 [PATCH] mm/sl[aou]b: make kfree() aware of error pointers Jiri Kosina
2014-09-09 23:21 ` Andrew Morton
2014-09-10  5:05   ` Jiri Kosina
2014-09-10  5:11     ` Andrew Morton
2014-09-10  6:36       ` Dan Carpenter
2014-09-10 13:56         ` Theodore Ts'o
2014-09-10 14:27           ` Dave Jones
2014-09-10 14:07     ` Theodore Ts'o
2014-09-10 14:24       ` Jiri Kosina
2014-09-10 14:33         ` Andrey Ryabinin
2014-09-10 14:42           ` Jiri Kosina
2014-09-10 15:43         ` Christoph Lameter
2014-09-10 14:26       ` Jiri Kosina
2014-09-10 15:21         ` Dan Carpenter
2014-09-10 15:28           ` Jiri Kosina
2014-09-10 15:53             ` Dan Carpenter
2014-09-10 19:40               ` Theodore Ts'o
2014-09-11 14:14             ` Rasmus Villemoes
2014-09-10 14:22     ` Christoph Lameter
2014-09-10  5:15   ` Valdis.Kletnieks
2014-09-10  6:51     ` Dan Carpenter
2014-09-10 13:59   ` Christoph Lameter

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