From: Vladimir Davydov <vdavydov@parallels.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@suse.cz>, Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH -mm] slab: update_memcg_params: explicitly check that old array != NULL
Date: Mon, 26 Jan 2015 13:45:34 +0300 [thread overview]
Message-ID: <20150126104534.GA28978@esperanza> (raw)
In-Reply-To: <20150126101902.GC6507@mwanda>
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
--
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>
next prev parent reply other threads:[~2015-01-26 10:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-26 8:56 [mmotm:master 200/417] mm/slab_common.c:166 update_memcg_params() warn: variable dereferenced before check 'old' (see line 162) Dan Carpenter
2015-01-26 10:01 ` [PATCH -mm] slab: update_memcg_params: explicitly check that old array != NULL Vladimir Davydov
2015-01-26 10:23 ` Dan Carpenter
2015-01-26 10:45 ` Vladimir Davydov [this message]
2015-01-26 15:13 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150126104534.GA28978@esperanza \
--to=vdavydov@parallels.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=dan.carpenter@oracle.com \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).