lkml.org 
[lkml]   [2015]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH -mm] slab: update_memcg_params: explicitly check that old array != NULL
On Mon, Jan 26, 2015 at 01:23:05PM +0300, Dan Carpenter wrote:
> On Mon, Jan 26, 2015 at 01:01:19PM +0300, Vladimir Davydov wrote:
> > This warning is false-positive, because @old equals NULL iff
> > @memcg_nr_cache_ids equals 0.
>
> I don't see how it could be a false positive. The "old" pointer is
> dereferenced inside the call to memset() so unless memset is a macro the
> compiler isn't going to optimize the dereference away.

old->entries is not dereferenced: memcg_cache_array->entries is not a
pointer - it is embedded to the memcg_cache_array struct.

>
>
> //----- test code
>
> void frob(void *p){}
>
> struct foo {
> int *x, *y, *z;
> };
>
> int main(void)
> {
> struct foo *x = NULL;
>
> frob(x->y);
>
> return 0;
> }
>
> //---- end
>
>
> If we compile with gcc test.c then it segfaults. With -02 the compiler
> is able to tell that frob() is an empty function and it doesn't
> segfault. In the kernel code, there is no way for the compiler to
> optimize the memset() away so it will Oops.

Just change

- int *x, *y, *z;
+ int *x, *z;
+ int *y[0];

and it won't.

Thanks,
Vladimir


\
 
 \ /
  Last update: 2015-01-26 12:01    [W:0.086 / U:0.632 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site