lkml.org 
[lkml]   [2014]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] mm/sl[aou]b: make kfree() aware of error pointers
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


\
 
 \ /
  Last update: 2014-09-10 00:01    [W:0.278 / U:2.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site