Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1569064
| From | Linus Torvalds <torvalds@linux-foundation.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' |
| Date | 2017-01-29 00:10 +0100 |
| Message-ID | <t4Ki6-7Iv-13@gated-at.bofh.it> (permalink) |
| References | <t4JvH-7bG-7@gated-at.bofh.it> <t4JFo-7fe-35@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Sat, Jan 28, 2017 at 2:11 PM, Ingo Molnar <mingo@kernel.org> wrote:
> Use a stricter type for struct e820_entry. Add a build-time check to make
> sure the compiler won't ever pack the enum into a field smaller than
> 'int'.
I'm not sure this is a good idea. In fact, I'm pretty sure it's a horrible idea.
The compiler that *users* use might decide that the "enum" fits in a
8-bit unsigned char, and decide to use that. The kernel build won't
notice and the BUG_ON() won't help, because we use a different
compiler.
(Or even if it's the same compiler you can have build flags - the size
of an enum very much depends on various compiler options, particularly
"--short-enums" for gcc).
Basically, we should not use "enum"s in types exported to user space.
The size just isn't sufficiently well defined, and it's a maintenance
nightmare.
Use explicitly sized members only, please. No "enum".
Linus
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Ingo Molnar <mingo@kernel.org> - 2017-01-28 23:30 +0100
Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-29 00:10 +0100
Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Ingo Molnar <mingo@kernel.org> - 2017-01-29 10:30 +0100
[PATCH] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures Ingo Molnar <mingo@kernel.org> - 2017-01-29 16:30 +0100
Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-29 20:20 +0100
csiph-web