lkml.org 
[lkml]   [2012]   [Nov]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] regulator: max8925: fix compiler warnings
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.





\
 
 \ /
  Last update: 2012-11-26 04:41    [W:0.152 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site