Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2592807ybi; Mon, 17 Jun 2019 07:23:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqy78oYslz3HX/DCpmABG3VqUq/CG0Qvq+MgoUSU5MQa/wuwBr/OBeK0r1uouMurDvmAqCf4 X-Received: by 2002:a63:516:: with SMTP id 22mr27517696pgf.116.1560781408351; Mon, 17 Jun 2019 07:23:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560781408; cv=none; d=google.com; s=arc-20160816; b=JCGquUEZ+07ZyZ+r9X1fV2zl7N8T0nQZYGT0uP8qUNzbO0w0oeGX85am1QOibphHC3 wbju2TtAfTtKXZ8WyPSGalviVJkvKt5C8f/qyhCvTSoYMW7seBDBYGjGCe0PJygHdk40 mghSglxayJbuLcbLI5ZziCjry9l8+dyYCgnvABdhS0WCh6pl8pAJMVSLA5PEcDjSA7k6 ndRf25eE+fiwvG1aeq7SyXhrPRHjE3hyzygIWQdNp1SQ9W8lGttAnyCY80bBG1dGuhVW HaxnvuBWbm+zbBy1DRrn8B6PlW9ijEFVyEuY5XsCvbetvheQFoPKFGsz1m16htNFNUYs AkEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5j/jTwc8VDaf93BqO7lj+/1q92uGDgZVHM2UqM4CWlY=; b=pFvEUw0C3nmsXBN/59CJPwFNiyBw7mjHihOmKM0VuJE8Dnc/3NqF1MXL3Zwt0JRXOd 9CeBKwZFzgI/HynA6tW0h0hEtwDeHxWDOvnt/AHGPKqnzaDcvTzwoSn3eVjubdFOcM7R JvYg2Gj60hxZHiOVg4OOPtc2tNYANXqZ7XGDzaYoSr1zZ0CJ4NCJeyH44D9us/vkLz+Z eqiEblTvhfS6Gg5Oky2fL9qsLsEES5x+uyWNgyRTJBTuestevEHj3bXcPbnfnJse6WMS slP2encylaxGjzx9QFFOOAoAK9MRgobCJQrmq6xK2bwj2CSlWYrB/2xRsM1QjgzHmHUf Wlag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="JVXa/qhC"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si10290857pgs.115.2019.06.17.07.23.12; Mon, 17 Jun 2019 07:23:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="JVXa/qhC"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728216AbfFQOWe (ORCPT + 99 others); Mon, 17 Jun 2019 10:22:34 -0400 Received: from mail-ua1-f65.google.com ([209.85.222.65]:46493 "EHLO mail-ua1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726173AbfFQOWd (ORCPT ); Mon, 17 Jun 2019 10:22:33 -0400 Received: by mail-ua1-f65.google.com with SMTP id o19so3486251uap.13 for ; Mon, 17 Jun 2019 07:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=5j/jTwc8VDaf93BqO7lj+/1q92uGDgZVHM2UqM4CWlY=; b=JVXa/qhCRuxxyrm3QYu61qbsldvBE3wQwlEaG4aJ6KmZZDqxSxVBoxL7X+Bfv9s19n FqGqP132gRRKgT62AQVOONEtf/SJt2ghJilvkSa4JQHGsqaApo0oov0Mj0vMGUPmt7+t yoZlxe0qub725pKU1JvcLpMxnffbI5MgBWlmfiEzk456/K+nmEH3WzGdJQ+Le9MuYxQX Iu4qlnCRlsg7mSwQXDV0wqAnqSVcJCSK4d8VXNUNun2+GkmNlu+eLeKha0NgAmZFm4VP 7nygtt75mRK0j8B3LpWPUPRUJxtHpgPflQN89IGbLkITY35PkAdF36l05THa1gfaEOYA iODw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=5j/jTwc8VDaf93BqO7lj+/1q92uGDgZVHM2UqM4CWlY=; b=m2yY+qJ8TTK/Ji+JtPOyfphgBeXug646xFDLrbmkKJ9wIUQZKaG4TkcP2HgkxvG6pX V5fmjzWoWTUG8zzeg8Ik3FccG2KR1PT9BSntzUpI5MmOd5nSPwXa1vN7eXBp3ZtK08eL 2nJZ6hdgOYfgs+tWN8kaTrNR3N1deguIcBEcX8cypeIf235G5m8QAoRFDltnqH8GxdPM zUFZ/huCQ1Uf9ZmLqlcPc9Le7XLTf/zlhLRQjxlr/C/fNQriH9lTu+4/Xk0qPAP+cT+w rzVev3w7lcc2JAfyAEcp/gyQTEibGbKcXzosyCkEOnBx6iJ2UyoLqTK0ApM/n5kprSWk 1lxQ== X-Gm-Message-State: APjAAAV8CN5sc3rt5GT7pwfKm1R5qNZduI5f5vwQqD/mN2Gwvk+sDCLn PvzUzUAw8EfTkR4+dacq1+3mvHHiBYFah2P9cD79Yw== X-Received: by 2002:ab0:30a3:: with SMTP id b3mr14495305uam.3.1560781351980; Mon, 17 Jun 2019 07:22:31 -0700 (PDT) MIME-Version: 1.0 References: <20190617131210.2190280-1-arnd@arndb.de> In-Reply-To: <20190617131210.2190280-1-arnd@arndb.de> From: Alexander Potapenko Date: Mon, 17 Jun 2019 16:22:19 +0200 Message-ID: Subject: Re: [PATCH] lib: test_meminit: fix -Wmaybe-uninitialized false positive To: Arnd Bergmann Cc: Andrew Morton , Kees Cook , Christoph Lameter , Nick Desaulniers , Kostya Serebryany , Dmitry Vyukov , Sandeep Patil , Laura Abbott , Jann Horn , Marco Elver , Stephen Rothwell , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 17, 2019 at 3:12 PM Arnd Bergmann wrote: > > The conditional logic is too complicated for the compiler to > fully comprehend: > > lib/test_meminit.c: In function 'test_meminit_init': > lib/test_meminit.c:236:5: error: 'buf_copy' may be used uninitialized in = this function [-Werror=3Dmaybe-uninitialized] > kfree(buf_copy); > ^~~~~~~~~~~~~~~ > lib/test_meminit.c:201:14: note: 'buf_copy' was declared here > > Simplify it by splitting out the non-rcu section. > > Fixes: af734ee6ec85 ("lib: introduce test_meminit module") > Signed-off-by: Arnd Bergmann Acked-by: Alexander Potapenko > --- > lib/test_meminit.c | 50 ++++++++++++++++++++++++---------------------- > 1 file changed, 26 insertions(+), 24 deletions(-) > > diff --git a/lib/test_meminit.c b/lib/test_meminit.c > index ed7efec1387b..7ae2183ff1f4 100644 > --- a/lib/test_meminit.c > +++ b/lib/test_meminit.c > @@ -208,35 +208,37 @@ static int __init do_kmem_cache_size(size_t size, b= ool want_ctor, > /* Check that buf is zeroed, if it must be. */ > fail =3D check_buf(buf, size, want_ctor, want_rcu, want_z= ero); > fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES = : 0); > + > + if (!want_rcu) { > + kmem_cache_free(c, buf); > + continue; > + } > + > /* > * If this is an RCU cache, use a critical section to ens= ure we > * can touch objects after they're freed. > */ > - if (want_rcu) { > - rcu_read_lock(); > - /* > - * Copy the buffer to check that it's not wiped o= n > - * free(). > - */ > - buf_copy =3D kmalloc(size, GFP_KERNEL); > - if (buf_copy) > - memcpy(buf_copy, buf, size); > - } > - kmem_cache_free(c, buf); > - if (want_rcu) { > - /* > - * Check that |buf| is intact after kmem_cache_fr= ee(). > - * |want_zero| is false, because we wrote garbage= to > - * the buffer already. > - */ > - fail |=3D check_buf(buf, size, want_ctor, want_rc= u, > - false); > - if (buf_copy) { > - fail |=3D (bool)memcmp(buf, buf_copy, siz= e); > - kfree(buf_copy); > - } > - rcu_read_unlock(); > + rcu_read_lock(); > + /* > + * Copy the buffer to check that it's not wiped on > + * free(). > + */ > + buf_copy =3D kmalloc(size, GFP_KERNEL); > + if (buf_copy) > + memcpy(buf_copy, buf, size); > + > + /* > + * Check that |buf| is intact after kmem_cache_free(). > + * |want_zero| is false, because we wrote garbage to > + * the buffer already. > + */ > + fail |=3D check_buf(buf, size, want_ctor, want_rcu, > + false); > + if (buf_copy) { > + fail |=3D (bool)memcmp(buf, buf_copy, size); > + kfree(buf_copy); > } > + rcu_read_unlock(); > } > kmem_cache_destroy(c); > > -- > 2.20.0 > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg