From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D9F7C433E6 for ; Sat, 20 Jun 2020 03:30:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0305823137 for ; Sat, 20 Jun 2020 03:30:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ASP8ZYf5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0305823137 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8960B6B00AA; Fri, 19 Jun 2020 23:30:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81D5A6B00AB; Fri, 19 Jun 2020 23:30:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64A5A6B00AC; Fri, 19 Jun 2020 23:30:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0009.hostedemail.com [216.40.44.9]) by kanga.kvack.org (Postfix) with ESMTP id 3C79E6B00AA for ; Fri, 19 Jun 2020 23:30:31 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F0ACC181AC9CC for ; Sat, 20 Jun 2020 03:30:30 +0000 (UTC) X-FDA: 76948162620.03.nose88_370af9b26e1e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id CC37028A4E8 for ; Sat, 20 Jun 2020 03:30:30 +0000 (UTC) X-HE-Tag: nose88_370af9b26e1e X-Filterd-Recvd-Size: 6595 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Sat, 20 Jun 2020 03:30:30 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id n9so4819074plk.1 for ; Fri, 19 Jun 2020 20:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QE7doATfVKyRNIS6o4GV46rwBSEL831INB+q/+9Rmh4=; b=ASP8ZYf5F8e3CyJ7PlH33MV/i7ui6qpJA/mDIbM14iTBLSGrg0GdC9kyTZr/lfh7CG GXzC9dz7nRwrAYeG29S+Q/THEeaVI5eUgF5DSRnMeurjTMSJnbVmhuDSeU19AKii4S2r YKBS0Qn5aMH95xmZNn8/myVX4U8ajBfLEQ9mc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QE7doATfVKyRNIS6o4GV46rwBSEL831INB+q/+9Rmh4=; b=rIkX52AiUEqA71G4Ogqim/+CdN+gFmBczEZR5jSyHVk4G1ea18bRwysjnlADN4vVig fGLkjlz0sHE+2tK2s3aA8PIRrZ1rQMX2WvlDzFYKhDYMG93XCkSZjTJNrmmatRa0Dbcj z9Nfvi/qQkKfkna0isQEErGckcb3SG8yUkGaefY9Tjhf0dlrmPhojdtkwepFT8WC6pIM 31egEbNCHC69qZp6f50zyHd0D+55Lr0cmWBCWRBrxoWeRzkSaKnDniHLNNakRbXk313t BSjLNC3vwBDuNGTrJwZL0YA/DVrzLu/nlONk0WTiIaaM3mm8BqTCbVtLnU+AL2e7Vy7C LuSQ== X-Gm-Message-State: AOAM530Dk7HJd432OwQKmN/7bDgQNa6t+zGyUYb0uGHiD0dc3bGHVgR/ J2Uj7cYge+OsfvDF2qqkjPtRdg== X-Google-Smtp-Source: ABdhPJwXvH55Kn4Xp+SPGU8vAiaQb11ixD/33bxeYcW2UOZTzvT5qr6VlXigT0w5zzrZdxmh+dRSYw== X-Received: by 2002:a17:90a:220f:: with SMTP id c15mr6886989pje.129.1592623829622; Fri, 19 Jun 2020 20:30:29 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id r7sm2178138pfc.183.2020.06.19.20.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 20:30:26 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Linus Torvalds , Bart van Assche , Miguel Ojeda , Nathan Chancellor , Sedat Dilek , Alexander Potapenko , Joe Perches , Andy Whitcroft , x86@kernel.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, b43-dev@lists.infradead.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-wireless@vger.kernel.org, linux-ide@vger.kernel.org, linux-clk@vger.kernel.org, linux-spi@vger.kernel.org, linux-mm@kvack.org, clang-built-linux@googlegroups.com Subject: [PATCH v2 16/16] compiler: Remove uninitialized_var() macro Date: Fri, 19 Jun 2020 20:30:06 -0700 Message-Id: <20200620033007.1444705-16-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200620033007.1444705-1-keescook@chromium.org> References: <20200620033007.1444705-1-keescook@chromium.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: CC37028A4E8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Using uninitialized_var() is dangerous as it papers over real bugs[1] (or can in the future), and suppresses unrelated compiler warnings (e.g. "unused variable"). If the compiler thinks it is uninitialized, either simply initialize the variable or make compiler changes. As recommended[2] by[3] Linus[4], remove the macro. With the recent change to disable -Wmaybe-uninitialized in v5.7 in commit 78a5255ffb6a ("Stop the ad-hoc games with -Wno-maybe-initialized"), this is likely the best time to make this treewide change. [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.co= m/ [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=3D1TGqCR5vQkCzWJ0QxK6Cern= OU6eedsudAixw@mail.gmail.com/ [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz= 9knmPuXhOeg@mail.gmail.com/ [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=3DyVJu65TpLg= N_ybYNv0VEOKA@mail.gmail.com/ Suggested-by: Linus Torvalds Reviewed-by: Bart van Assche Reviewed-by: Miguel Ojeda Tested-by: Nathan Chancellor Tested-by: Sedat Dilek Signed-off-by: Kees Cook --- include/linux/compiler-clang.h | 2 -- include/linux/compiler-gcc.h | 6 ------ tools/include/linux/compiler.h | 2 -- tools/virtio/linux/kernel.h | 2 -- 4 files changed, 12 deletions(-) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clan= g.h index ee37256ec8bd..f2371b83aaf2 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -5,8 +5,6 @@ =20 /* Compiler specific definitions for Clang compiler */ =20 -#define uninitialized_var(x) x =3D *(&(x)) - /* same as gcc, this was present in clang-2.6 so we can assume it works * with any version that can compile the kernel */ diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 7dd4e0349ef3..84e099a87383 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -59,12 +59,6 @@ (typeof(ptr)) (__ptr + (off)); \ }) =20 -/* - * A trick to suppress uninitialized variable warning without generating= any - * code - */ -#define uninitialized_var(x) x =3D x - #ifdef CONFIG_RETPOLINE #define __noretpoline __attribute__((__indirect_branch__("keep"))) #endif diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compile= r.h index 9f9002734e19..2f2f4082225e 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -111,8 +111,6 @@ # define noinline #endif =20 -#define uninitialized_var(x) x =3D *(&(x)) - #include =20 /* diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h index 6683b4a70b05..1e14ab967c11 100644 --- a/tools/virtio/linux/kernel.h +++ b/tools/virtio/linux/kernel.h @@ -109,8 +109,6 @@ static inline void free_page(unsigned long addr) const typeof( ((type *)0)->member ) *__mptr =3D (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) =20 -#define uninitialized_var(x) x =3D x - # ifndef likely # define likely(x) (__builtin_expect(!!(x), 1)) # endif --=20 2.25.1