From: Joakim Tjernlund <joakim.tjernlund@infinera.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Joakim Tjernlund <joakim.tjernlund@infinera.com>
Subject: [PATCH 2/2] compiler.h: fix C++ uninitialized const issue
Date: Tue, 21 Feb 2017 16:24:05 +0100 [thread overview]
Message-ID: <20170221152405.7552-2-joakim.tjernlund@infinera.com> (raw)
In-Reply-To: <20170221152405.7552-1-joakim.tjernlund@infinera.com>
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*)::<anonymous>'
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 <joakim.tjernlund@infinera.com>
---
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
next prev parent reply other threads:[~2017-02-21 15:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-21 15:24 [PATCH 1/2] Correct function definition for C++ Joakim Tjernlund
2017-02-21 15:24 ` Joakim Tjernlund [this message]
2017-02-22 7:10 ` Greg KH
2017-02-22 7:50 ` Joakim Tjernlund
2017-02-22 13:03 ` greg
2017-02-22 14:00 ` Joakim Tjernlund
2017-02-22 14:22 ` greg
2017-02-22 16:25 ` Joakim Tjernlund
2017-02-28 23:15 ` Thomas Backlund
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=20170221152405.7552-2-joakim.tjernlund@infinera.com \
--to=joakim.tjernlund@infinera.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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).