From: Qing Xu <qingx@marvell.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: "lrg@ti.com" <lrg@ti.com>,
"haojian.zhuang@gmail.com" <haojian.zhuang@gmail.com>,
Chao Xie <cxie4@marvell.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] regulator: max8925: fix compiler warnings
Date: Mon, 26 Nov 2012 11:07:25 +0800 [thread overview]
Message-ID: <50B2DCED.5080509@marvell.com> (raw)
In-Reply-To: <20121124175554.GF4719@opensource.wolfsonmicro.com>
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.
prev parent reply other threads:[~2012-11-26 3:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50B2DCED.5080509@marvell.com \
--to=qingx@marvell.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=cxie4@marvell.com \
--cc=haojian.zhuang@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).