lkml.org 
[lkml]   [2015]   [Sep]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: kfree a pointer "from the middle" causing protection faults
From
On Wed, Sep 2, 2015 at 8:02 AM, Muni Sekhar <munisekharrms@gmail.com> wrote:
> [ Please keep me in CC as I'm not subscribed to the list]
>
> Hello,
>
>
> I am getting protection faults in different kernel modules if I try to
> free a pointer "from the middle" for example, look at the following
> code:
>
>
> u8 *buf;
>
>
> buf = kzalloc( 100 , GFP_KERNEL );
>
> …
>
> buf = buf + 50;
>
> …
>
> Kfree(buf);
>
>
>
>
> I would like to know, why the above code is causing protection faults
> in other kernel modules?

Because you can not make a "hole" in returned memory like that, you
can only free entire block allocated by k*alloc and you need to pass
the original pointer in.

Thanks.

--
Dmitry


\
 
 \ /
  Last update: 2015-09-02 18:41    [W:0.057 / U:0.992 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site