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


Groups > linux.kernel > #1336127 > unrolled thread

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

Started byKrzysztof Kozlowski <k.kozlowski@samsung.com>
First post2016-02-17 09:20 +0100
Last post2016-02-18 21:20 +0100
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [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

#1336127 — [RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for some of preprocessors

FromKrzysztof Kozlowski <k.kozlowski@samsung.com>
Date2016-02-17 09:20 +0100
Subject[RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for some of preprocessors
Message-ID<r35v5-3Dc-17@gated-at.bofh.it>
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.

Additionally add missing BUILD_BUG_ON check for S2MPS15 device (the
check ensures that internal arrays are big enough to hold data for all
of regulators on all devices).

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

---

See results when UBSAN is enabled:
http://arm-soc.lixom.net/buildlogs/arm-soc/v4.5-rc4-39-g0d7baf0/buildall.arm.exynos_defconfig.log.failed
---
 drivers/regulator/s2mps11.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 3242ffc0cb25..df553fb40d82 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -1090,26 +1090,27 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
 	case S2MPS11X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
 		regulators = s2mps11_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
 		break;
 	case S2MPS13X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators);
 		regulators = s2mps13_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
 		break;
 	case S2MPS14X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
 		regulators = s2mps14_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
 		break;
 	case S2MPS15X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps15_regulators);
 		regulators = s2mps15_regulators;
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
 		break;
 	case S2MPU02:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
 		regulators = s2mpu02_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
 		break;
 	default:
 		dev_err(&pdev->dev, "Invalid device type: %u\n",
-- 
2.5.0

[toc] | [next] | [standalone]


#1336739 — RE: [RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for some of preprocessors

From"Keller, Jacob E" <jacob.e.keller@intel.com>
Date2016-02-17 21:40 +0100
SubjectRE: [RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for some of preprocessors
Message-ID<r3h3c-3bi-21@gated-at.bofh.it>
In reply to#1336127
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)

Thanks,
Jake

[toc] | [prev] | [next] | [standalone]


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

FromKrzysztof Kozlowski <k.kozlowski@samsung.com>
Date2016-02-18 01:30 +0100
SubjectRe: [RFT] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON for some of preprocessors
Message-ID<r3kDM-5JG-17@gated-at.bofh.it>
In reply to#1336739
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

[toc] | [prev] | [next] | [standalone]


#1337672 — Applied "regulator: s2mps11: Simplify expression used in BUILD_BUG_ON" to the regulator tree

FromMark Brown <broonie@kernel.org>
Date2016-02-18 21:20 +0100
SubjectApplied "regulator: s2mps11: Simplify expression used in BUILD_BUG_ON" to the regulator tree
Message-ID<r3Ddn-2wj-11@gated-at.bofh.it>
In reply to#1336127
The patch

   regulator: s2mps11: Simplify expression used in BUILD_BUG_ON

has been applied to the regulator tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 297eaaa6d0bf09a91045e1d8c9b1e555d8b91d8a Mon Sep 17 00:00:00 2001
From: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Date: Thu, 18 Feb 2016 09:35:07 +0900
Subject: [PATCH] regulator: s2mps11: Simplify expression used in BUILD_BUG_ON

Following BUILD_BUG_ON using a variable fails for some of the compilers
and optimization levels (reported for gcc 4.9):
	var = ARRAY_SIZE(s2mps15_regulators);
	BUILD_BUG_ON(S2MPS_REGULATOR_MAX < var);
Fix this by using ARRAY_SIZE directly.

Additionally add missing BUILD_BUG_ON check for S2MPS15 device (the
check ensures that internal arrays are big enough to hold data for all
of regulators on all devices).

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/regulator/s2mps11.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 3242ffc0cb25..df553fb40d82 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -1090,26 +1090,27 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
 	case S2MPS11X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
 		regulators = s2mps11_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
 		break;
 	case S2MPS13X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators);
 		regulators = s2mps13_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
 		break;
 	case S2MPS14X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
 		regulators = s2mps14_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
 		break;
 	case S2MPS15X:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mps15_regulators);
 		regulators = s2mps15_regulators;
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
 		break;
 	case S2MPU02:
 		s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
 		regulators = s2mpu02_regulators;
-		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
+		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
 		break;
 	default:
 		dev_err(&pdev->dev, "Invalid device type: %u\n",
-- 
2.7.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web