lkml.org 
[lkml]   [2014]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mm/sl[aou]b: make kfree() aware of error pointers
On Tue, 9 Sep 2014 23:25:28 +0200 (CEST) Jiri Kosina <jkosina@suse.cz> wrote:

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

kfree() is quite a hot path to which this will add overhead. And we
have (as far as we know) no code which will actually use this at
present.

How about a new

kfree_safe(...)
{
if (IS_ERR(...))
return;
if (other-stuff-when-we-think-of-it)
return;
kfree(...);
}

?


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