From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752421AbdBUPcK (ORCPT ); Tue, 21 Feb 2017 10:32:10 -0500 Received: from smtp.transmode.se ([31.15.61.139]:56381 "EHLO smtp.transmode.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbdBUPcD (ORCPT ); Tue, 21 Feb 2017 10:32:03 -0500 X-Greylist: delayed 470 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Feb 2017 10:32:02 EST From: Joakim Tjernlund To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Joakim Tjernlund Subject: [PATCH 2/2] compiler.h: fix C++ uninitialized const issue Date: Tue, 21 Feb 2017 16:24:05 +0100 Message-Id: <20170221152405.7552-2-joakim.tjernlund@infinera.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170221152405.7552-1-joakim.tjernlund@infinera.com> References: <20170221152405.7552-1-joakim.tjernlund@infinera.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org C++ does not like the union { typeof(x) __val; char __c[1]; } __u construct for const types: error: uninitialized const member in 'union atomic_read(const atomic_t*)::' Address this by creating a C++ version of READ_ONCE where this union is initialized: union { void _u(){}; typeof(x) __val; char __c[1]; } __u={0} To please gcc 6.3.0 also add in a _u(){} as default ctor. This makes C++ happy enough to build. Signed-off-by: Joakim Tjernlund --- include/linux/compiler.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index cf0fa5d..0a047fd 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -300,6 +300,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s * required ordering. */ +#ifndef __cplusplus #define __READ_ONCE(x, check) \ ({ \ union { typeof(x) __val; char __c[1]; } __u; \ @@ -309,6 +310,17 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \ __u.__val; \ }) +#else +#define __READ_ONCE(x, check) \ +({ \ + union { void _u(){}; typeof(x) __val; char __c[1]; } __u={0}; \ + if (check) \ + __read_once_size(&(x), __u.__c, sizeof(x)); \ + else \ + __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \ + __u.__val; \ +}) +#endif #define READ_ONCE(x) __READ_ONCE(x, 1) /* -- 2.10.2