From patchwork Sat Jun 20 03:30:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11615493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72AAE14E3 for ; Sat, 20 Jun 2020 03:31:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5370323340 for ; Sat, 20 Jun 2020 03:31:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ASP8ZYf5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733288AbgFTDbe (ORCPT ); Fri, 19 Jun 2020 23:31:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733212AbgFTDbQ (ORCPT ); Fri, 19 Jun 2020 23:31:16 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 109AEC05BD40 for ; Fri, 19 Jun 2020 20:30:30 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id k6so4799099pll.9 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=DGzfARuCXN4pFWeKE42Il/5yxCdMVBRrr7H9WOlZvVoqYosC0FVKXaRLYwPhh8BQ1i pA+8KxC1ck1o/t9bA7V/nfJJW4+smURvNRMw/xpJsOONDwaNbUDxhdNcdSOpLF8jf8mA F6WLwjSIr9DTARWU8njrjTG6EC9RqdIYLe2N4TmNrrt05Zvw7+IWTYQdu6eIZAuZrZYF XIwOxEuYUXnxaw1F71w9hFog7ERIwX807wSqI6UncWabDu1c/ff55yrQkl9yTFpCSjeA BdyF7iStEPVrgvKjiUvmp0FYX15pt0vQHncKWtzUJh5+yqckEmC3YUkqgcWVwWK0YKiE a1bw== X-Gm-Message-State: AOAM533i/21JPglWmos0L+8iLkODxeux1jDcA8XI0fVisiZXKgo+HPze JyH/YY2bnGcM4ZRfOkZBGYANhg== 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 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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.com/ [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/ [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/ [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_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-clang.h index ee37256ec8bd..f2371b83aaf2 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -5,8 +5,6 @@ /* Compiler specific definitions for Clang compiler */ -#define uninitialized_var(x) x = *(&(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)); \ }) -/* - * A trick to suppress uninitialized variable warning without generating any - * code - */ -#define uninitialized_var(x) x = x - #ifdef CONFIG_RETPOLINE #define __noretpoline __attribute__((__indirect_branch__("keep"))) #endif diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index 9f9002734e19..2f2f4082225e 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -111,8 +111,6 @@ # define noinline #endif -#define uninitialized_var(x) x = *(&(x)) - #include /* 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 = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define uninitialized_var(x) x = x - # ifndef likely # define likely(x) (__builtin_expect(!!(x), 1)) # endif