Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1336900

Re: [RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for some of preprocessors

From Krzysztof Kozlowski <k.kozlowski@samsung.com>
Newsgroups linux.kernel
Subject Re: [RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for some of preprocessors
Date 2016-02-18 01:30 +0100
Message-ID <r3kDM-5JG-17@gated-at.bofh.it> (permalink)
References <r35v5-3Dc-17@gated-at.bofh.it> <r3h3c-3bi-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 18.02.2016 05:37, Keller, Jacob E wrote:
> Hi,
> 
>> -----Original Message-----
>> From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
>> owner@vger.kernel.org] On Behalf Of Krzysztof Kozlowski
>> Sent: Wednesday, February 17, 2016 12:11 AM
>> To: Sangbeom Kim <sbkim73@samsung.com>; Krzysztof Kozlowski
>> <k.kozlowski@samsung.com>; Liam Girdwood <lgirdwood@gmail.com>;
>> Mark Brown <broonie@kernel.org>; linux-kernel@vger.kernel.org; linux-
>> samsung-soc@vger.kernel.org
>> Cc: Arnd Bergmann <arnd@arndb.de>
>> Subject: [RFT] regulator: s2mps11: Simplify expression used in
>> BUILD_BUG_ON for some of preprocessors
>>
>> Apparently some preprocessors have problems with interpreting
>> BUILD_BUG_ON such as:
>> 	var = ARRAY_SIZE(s2mps15_regulators);
>> 	BUILD_BUG_ON(S2MPS_REGULATOR_MAX < var);
>> so let make it more obvious for them.
>>
> 
> Doesn't have much to do with the preprocessor, but rather exactly how the compiler optimizes the variable. Some kernel configurations also impact this, and it heavily depends on whether the compiler actually optimizes away the variable. BUILD_BUG_ON may work a lot of the time, depending heavily on the compiler.
> 
> BUILD_BUG_ON only works for constant expressions, so it is safer to put the value in directly, because using a variable will only work if the compiler optimizes the use of a variable away entirely. In this case it is somewhat surprising that it doesn't, but would depend on what compiler version and what kernel build rules you were using. For example allmodconfig ends up selecting everything yes if it's not a module for kernel build options and results in some BUILD_BUG_ON failures because of that)

Right, thanks for detailed explanation. Arnd confirmed that patch fixes
encountered issue (gcc 4.9 with UBSAN).

I'll change the commit message and re-submit.

Best regards,
Krzysztof

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for  some of preprocessors Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-02-17 09:20 +0100
  RE: [RFT] regulator: s2mps11: Simplify expression used in  BUILD_BUG_ON for some of preprocessors "Keller, Jacob E" <jacob.e.keller@intel.com> - 2016-02-17 21:40 +0100
    Re: [RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON  for some of preprocessors Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-02-18 01:30 +0100
  Applied "regulator: s2mps11: Simplify expression used in BUILD_BUG_ON" to the regulator tree Mark Brown <broonie@kernel.org> - 2016-02-18 21:20 +0100

csiph-web