From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752548AbdA1XHM (ORCPT ); Sat, 28 Jan 2017 18:07:12 -0500 Received: from mail-ot0-f193.google.com ([74.125.82.193]:35238 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752401AbdA1XHF (ORCPT ); Sat, 28 Jan 2017 18:07:05 -0500 MIME-Version: 1.0 In-Reply-To: <1485641531-22124-38-git-send-email-mingo@kernel.org> References: <1485641531-22124-1-git-send-email-mingo@kernel.org> <1485641531-22124-38-git-send-email-mingo@kernel.org> From: Linus Torvalds Date: Sat, 28 Jan 2017 15:07:03 -0800 X-Google-Sender-Auth: Y42oHG8YAYrCJ1A_KWndualEzi0 Message-ID: Subject: Re: [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' To: Ingo Molnar Cc: Linux Kernel Mailing List , Andrew Morton , Andy Lutomirski , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Yinghai Lu Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 28, 2017 at 2:11 PM, Ingo Molnar 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