* [PATCH] Regulator: Suppress compiler warnings
@ 2015-08-31 16:41 Keith Busch
2015-09-01 0:52 ` Krzysztof Kozlowski
0 siblings, 1 reply; 4+ messages in thread
From: Keith Busch @ 2015-08-31 16:41 UTC (permalink / raw)
To: linux-kernel; +Cc: Liam Girdwood, Mark Brown, Keith Busch
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 <keith.busch@intel.com>
---
drivers/regulator/helpers.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index 3bbb326..bb5b22a 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -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);
--
1.7.10.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Regulator: Suppress compiler warnings
2015-08-31 16:41 [PATCH] Regulator: Suppress compiler warnings Keith Busch
@ 2015-09-01 0:52 ` Krzysztof Kozlowski
2015-09-01 13:09 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2015-09-01 0:52 UTC (permalink / raw)
To: Keith Busch; +Cc: linux-kernel, Liam Girdwood, Mark Brown
2015-09-01 1:41 GMT+09:00 Keith Busch <keith.busch@intel.com>:
> 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 <keith.busch@intel.com>
> ---
> drivers/regulator/helpers.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
> index 3bbb326..bb5b22a 100644
> --- a/drivers/regulator/helpers.c
> +++ b/drivers/regulator/helpers.c
> @@ -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
> @@ -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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Regulator: Suppress compiler warnings
2015-09-01 0:52 ` Krzysztof Kozlowski
@ 2015-09-01 13:09 ` Mark Brown
2015-09-01 18:40 ` Keith Busch
0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2015-09-01 13:09 UTC (permalink / raw)
To: Krzysztof Kozlowski; +Cc: Keith Busch, linux-kernel, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 1141 bytes --]
On Tue, Sep 01, 2015 at 09:52:13AM +0900, Krzysztof Kozlowski wrote:
> 2015-09-01 1:41 GMT+09:00 Keith Busch <keith.busch@intel.com>:
> > 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)
> > {
> > - 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?
Right, plus this will shut up valid compiler warnings which is poor
practice anyway. I'd say this is a bug in the compiler.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Regulator: Suppress compiler warnings
2015-09-01 13:09 ` Mark Brown
@ 2015-09-01 18:40 ` Keith Busch
0 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2015-09-01 18:40 UTC (permalink / raw)
To: Mark Brown; +Cc: Krzysztof Kozlowski, Keith Busch, linux-kernel, Liam Girdwood
On Tue, 1 Sep 2015, Mark Brown wrote:
> On Tue, Sep 01, 2015 at 09:52:13AM +0900, Krzysztof Kozlowski wrote:
>> 2015-09-01 1:41 GMT+09:00 Keith Busch <keith.busch@intel.com>:
>>> 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?
>
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-01 18:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-31 16:41 [PATCH] Regulator: Suppress compiler warnings Keith Busch
2015-09-01 0:52 ` Krzysztof Kozlowski
2015-09-01 13:09 ` Mark Brown
2015-09-01 18:40 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®