linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: max8925: fix compiler warnings
@ 2012-11-22  2:11 Qing Xu
  2012-11-23  1:41 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Qing Xu @ 2012-11-22  2:11 UTC (permalink / raw)
  To: qingx, broonie, lrg, haojian.zhuang, cxie4, linux-kernel

From: Qing Xu <qingx@marvell.com>

Fixed following compiler warning:

- drivers/regulator/max8925-regulator.c:269:51: warning:
  'regulator_idx' may be used uninitialized in this function
  [-Wmaybe-uninitialized]

Signed-off-by: Qing Xu <qingx@marvell.com>
---
 drivers/regulator/max8925-regulator.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index 2b54979..187b29b 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -282,7 +282,8 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev)
 	struct max8925_regulator_info *ri;
 	struct resource *res;
 	struct regulator_dev *rdev;
-	int i, regulator_idx;
+	int i;
+	int regulator_idx = 0;
 
 	res = platform_get_resource(pdev, IORESOURCE_REG, 0);
 	if (!res) {
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: max8925: fix compiler warnings
  2012-11-22  2:11 [PATCH] regulator: max8925: fix compiler warnings Qing Xu
@ 2012-11-23  1:41 ` Mark Brown
  2012-11-23  2:27   ` Qing Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2012-11-23  1:41 UTC (permalink / raw)
  To: Qing Xu; +Cc: lrg, haojian.zhuang, cxie4, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 345 bytes --]

On Thu, Nov 22, 2012 at 10:11:06AM +0800, Qing Xu wrote:

> -	int i, regulator_idx;
> +	int i;
> +	int regulator_idx = 0;

This sort of fix is rarely good without some analysis as to why this is
a sensible initialisation to do, just unconditionally initialising may
be masking a real issue in the control flow which the compiler has
identified.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: max8925: fix compiler warnings
  2012-11-23  1:41 ` Mark Brown
@ 2012-11-23  2:27   ` Qing Xu
  2012-11-24 17:55     ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Qing Xu @ 2012-11-23  2:27 UTC (permalink / raw)
  To: Mark Brown; +Cc: lrg, haojian.zhuang, Chao Xie, linux-kernel

On 11/23/2012 09:41 AM, Mark Brown wrote:
> On Thu, Nov 22, 2012 at 10:11:06AM +0800, Qing Xu wrote:
>
>> -	int i, regulator_idx;
>> +	int i;
>> +	int regulator_idx = 0;
> This sort of fix is rarely good without some analysis as to why this is
> a sensible initialisation to do, just unconditionally initialising may
> be masking a real issue in the control flow which the compiler has
> identified.
In my build environment, there is no such compiler warning. :(

Adding this patch is just want to avoid kbuild test robot's warning.
But, in fact, it is not necessary to initialize regulator_idx.


         for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
                 ri = &max8925_regulator_info[i];
                 if (ri->vol_reg == res->start) {

****** if regulator_idx can not get a match "i" here, it will return
-EINVAL in below code

                         regulator_idx = i;
                         break;
                 }
         }

         if (i == ARRAY_SIZE(max8925_regulator_info)) {
                 dev_err(&pdev->dev, "Failed to find regulator %llu\n",
                         (unsigned long long)res->start);
                 return -EINVAL;
         }

How to solve such compiler warning?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: max8925: fix compiler warnings
  2012-11-23  2:27   ` Qing Xu
@ 2012-11-24 17:55     ` Mark Brown
  2012-11-26  3:07       ` Qing Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2012-11-24 17:55 UTC (permalink / raw)
  To: Qing Xu; +Cc: lrg, haojian.zhuang, Chao Xie, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 940 bytes --]

On Fri, Nov 23, 2012 at 10:27:12AM +0800, Qing Xu wrote:

> But, in fact, it is not necessary to initialize regulator_idx.

>         for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
>                 ri = &max8925_regulator_info[i];
>                 if (ri->vol_reg == res->start) {

> ****** if regulator_idx can not get a match "i" here, it will return
> -EINVAL in below code

>                         regulator_idx = i;
>                         break;
>                 }
>         }

>         if (i == ARRAY_SIZE(max8925_regulator_info)) {
>                 dev_err(&pdev->dev, "Failed to find regulator %llu\n",
>                         (unsigned long long)res->start);
>                 return -EINVAL;
>         }

> How to solve such compiler warning?

Typically by reporting a compiler bug, though sometimes in the process
of doing that one finds out that there's some non-obvious way in which
the code can break.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: max8925: fix compiler warnings
  2012-11-24 17:55     ` Mark Brown
@ 2012-11-26  3:07       ` Qing Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Qing Xu @ 2012-11-26  3:07 UTC (permalink / raw)
  To: Mark Brown; +Cc: lrg, haojian.zhuang, Chao Xie, linux-kernel

On 11/25/2012 01:55 AM, Mark Brown wrote:
> On Fri, Nov 23, 2012 at 10:27:12AM +0800, Qing Xu wrote:
>
>> But, in fact, it is not necessary to initialize regulator_idx.
>>          for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
>>                  ri = &max8925_regulator_info[i];
>>                  if (ri->vol_reg == res->start) {
>> ****** if regulator_idx can not get a match "i" here, it will return
>> -EINVAL in below code
>>                          regulator_idx = i;
>>                          break;
>>                  }
>>          }
>>          if (i == ARRAY_SIZE(max8925_regulator_info)) {
>>                  dev_err(&pdev->dev, "Failed to find regulator %llu\n",
>>                          (unsigned long long)res->start);
>>                  return -EINVAL;
>>          }
>> How to solve such compiler warning?
> Typically by reporting a compiler bug, though sometimes in the process
> of doing that one finds out that there's some non-obvious way in which
> the code can break.

It seems not like a compiler bug, its logic is:

for(...; i<xxx; ...) {
     if (...) {
         regulator_idx = i
         break;
     }
}

if (i == xxx)
     return ERROR;

If regulator_idx can not get a matched "i" value, code will return ERROR.
But it seems that compiler can not do so complex judge.
And, I think the code is safe even if regulator_idx is not initialized, also
because of the "return ERROR" judge.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-26  3:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22  2:11 [PATCH] regulator: max8925: fix compiler warnings Qing Xu
2012-11-23  1:41 ` Mark Brown
2012-11-23  2:27   ` Qing Xu
2012-11-24 17:55     ` Mark Brown
2012-11-26  3:07       ` Qing Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).