Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry'

From: Linus Torvalds
Date: Sat Jan 28 2017 - 18:07:16 EST


On Sat, Jan 28, 2017 at 2:11 PM, Ingo Molnar <mingo@xxxxxxxxxx> 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