Regulator: Suppress compiler warnings
PATCH 1/1 Regulator: Suppress compiler warnings
Some compilers complain of possible uninitialized variable usage, like the following:
drivers/regulator/helpers.c: In function ‘regulator_get_bypass_regmap’:
drivers/regulator/helpers.c:463:16: warning: ‘val’ may be used uninitialized in this function [-Wuninitialized]
The code is safe though, and only uses the variables if they were successfully set, so suppressing the warning with uninitialized_val.
--- drivers/regulator/helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/regulator/helpers.c +3 -3
@@ -30,7 +30,7 @@*/ int regulator_is_enabled_regmap (struct regulator_dev *rdev) { -unsigned int val; +unsigned int uninitialized_var (val );int ret; ret =regmap_read (rdev->regmap, rdev->desc->enable_reg, &val);
@@ -114,7 +114,7 @@ EXPORT_SYMBOL_GPL(regulator_disable_regmap);*/ int regulator_get_voltage_sel_regmap (struct regulator_dev *rdev) { -unsigned int val; +unsigned int uninitialized_var (val );int ret; ret =regmap_read (rdev->regmap, rdev->desc->vsel_reg, &val);
@@ -453,7 +453,7 @@ EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap);*/ int regulator_get_bypass_regmap (struct regulator_dev *rdev,bool *enable) { -unsigned int val; +unsigned int uninitialized_var (val );int ret; ret =regmap_read (rdev->regmap, rdev->desc->bypass_reg, &val);
Signature · 1 line
1.7.10.4
2015-09-01 1:41 GMT+09:00 Keith Busch <[email protected]>:
Quoted 19 lines
Some compilers complain of possible uninitialized variable usage, like the following:
drivers/regulator/helpers.c: In function ‘regulator_get_bypass_regmap’:
drivers/regulator/helpers.c:463:16: warning: ‘val’ may be used uninitialized in this function [-Wuninitialized]The code is safe though, and only uses the variables if they were successfully set, so suppressing the warning with
uninitialized_val.Signed-off-by Keith Busch <[email protected]>--- drivers/regulator/helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/regulator/helpers.c +0
-0
drivers/regulator/helpers.c line 36
Quoted 8 lines
drivers/regulator/helpers.c +1
-1@@ -30,7 +30,7 @@*/ int regulator_is_enabled_regmap (struct regulator_dev *rdev) { -unsigned int val; +unsigned int uninitialized_var (val );int ret; ret =regmap_read (rdev->regmap, rdev->desc->enable_reg, &val);
This is quite common pattern so such work-around should be added to many other functions leading to code obfuscation. Which compiler do you have in mind?
Best regards,
Krzysztof
Quoted 26 lines
drivers/regulator/helpers.c +2
-3@@ -114,7 +114,7 @@ EXPORT_SYMBOL_GPL(regulator_disable_regmap);*/ int regulator_get_voltage_sel_regmap (struct regulator_dev *rdev) { -unsigned int val; +unsigned int uninitialized_var (val );int ret; ret =regmap_read (rdev->regmap, rdev->desc->vsel_reg, &val);@@ -453,7 +453,7 @@ EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap);*/ int regulator_get_bypass_regmap (struct regulator_dev *rdev,bool *enable) { -unsigned int val; +unsigned int uninitialized_var (val );int ret; ret =regmap_read (rdev->regmap, rdev->desc->bypass_reg, &val); --1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Mark Brown
maintainerQuoted 16 lines · Krzysztof Kozlowski
2015-09-01 1:41 GMT+09:00 Keith Busch <[email protected]>:
Quoted 15 lines
Some compilers complain of possible uninitialized variable usage, like the following:
drivers/regulator/helpers.c: In function ‘regulator_get_bypass_regmap’:
drivers/regulator/helpers.c:463:16: warning: ‘val’ may be used uninitialized in this function [-Wuninitialized]The code is safe though, and only uses the variables if they were successfully set, so suppressing the warning with
uninitialized_val.int
regulator_is_enabled_regmap(struct regulator_dev *rdev){drivers/regulator/helpers.c +1
-1-unsigned int val; +unsigned int uninitialized_var (val );int ret;
Quoted 5 lines
Quoted 1 line
ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);This is quite common pattern so such work-around should be added to many other functions leading to code obfuscation. Which compiler do you have in mind?
Right, plus this will shut up valid compiler warnings which is poor practice anyway. I'd say this is a bug in the compiler.
Quoted 8 lines · Mark Brown
Quoted 7 lines · Krzysztof Kozlowski
2015-09-01 1:41 GMT+09:00 Keith Busch <[email protected]>:
Quoted 6 lines
int
regulator_is_enabled_regmap(struct regulator_dev *rdev){drivers/regulator/helpers.c +1
-1-unsigned int val; +unsigned int uninitialized_var (val );int ret;
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);This is quite common pattern so such work-around should be added to many other functions leading to code obfuscation. Which compiler do you have in mind?
Right, plus this will shut up valid compiler warnings which is poor practice anyway. I'd say this is a bug in the compiler.
Using gcc 4.7.2 with '-Os'. The warning does not happen when that option is not used, i.e. disable CONFIG_CC_OPTIMIZE_FOR_SIZE.
I will certainly try other gcc versions with the same config and see what happens.