From: dd diasemi <dd.diasemi@gmail.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: drivers/regulator/core.c: Fixes mapping inside regulator_mode_to_status() and makes it returning -EINVAL on invalid input.
Date: Tue, 10 Jan 2012 17:09:40 +0000 [thread overview]
Message-ID: <CAEqHmAtrUNKTxt3Q8x7=nZNp09ajhyYQn3DmAKd3OUib9hLBUQ@mail.gmail.com> (raw)
In-Reply-To: <20120110001447.GK30766@opensource.wolfsonmicro.com>
On Tue, Jan 10, 2012 at 12:14 AM, Mark Brown
<broonie@opensource.wolfsonmicro.com> wrote:
> On Tue, Jan 10, 2012 at 12:11:33AM +0000, dd diasemi wrote:
>
>> Making regulator_mode_to_status() returning an error allows to
>> simplify its usage:
>> ret = regulator_mode_to_status(regulator_get_mode(rdev));
>> if (ret < 0)
>> ret = -EIO;
>
> That code would definitely be less than ideal - if we got an error back
> from the attempt to read the mode we ought to be returning that error
> not squashing it down to a single value.
Yes, indeed.
>> If that behaviour is deliberate, I would suggest to make it explicit:
>> default:
>> - return 0;
>> + return REGULATOR_STATUS_OFF;
>
> That's not the deliberate behaviour, the deliberate behaviour is to
> return no mode if we didn't find one.
The behaviour is exactly the same in both cases, because
REGULATOR_STATUS_OFF == 0.
>From linux/regulator/driver.h:
enum regulator_status {
REGULATOR_STATUS_OFF,
REGULATOR_STATUS_ON,
REGULATOR_STATUS_ERROR,
/* fast/normal/idle/standby are flavors of "on" */
REGULATOR_STATUS_FAST,
REGULATOR_STATUS_NORMAL,
REGULATOR_STATUS_IDLE,
REGULATOR_STATUS_STANDBY,
};
So the only difference is that, the code:
return 0;
is not obvious but still it will be interpreted as:
return REGULATOR_STATUS_OFF;
by the caller of regulator_mode_to_status() when incorrect mode is passed.
Is it correct way to hide this behaviour rather than to make it explicit ?
And to set things up, should regulator_get_status() return negative
error code or REGULATOR_STATUS_OFF (0) on communication failure?
next prev parent reply other threads:[~2012-01-10 17:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-09 12:12 drivers/regulator/core.c: Fixes mapping inside regulator_mode_to_status() and makes it returning -EINVAL on invalid input Krystian Garbaciak
2012-01-09 16:14 ` Mark Brown
2012-01-09 19:20 ` dd diasemi
2012-01-09 20:07 ` Mark Brown
2012-01-10 0:11 ` dd diasemi
2012-01-10 0:14 ` Mark Brown
2012-01-10 17:09 ` dd diasemi [this message]
2012-01-10 17:14 ` Mark Brown
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='CAEqHmAtrUNKTxt3Q8x7=nZNp09ajhyYQn3DmAKd3OUib9hLBUQ@mail.gmail.com' \
--to=dd.diasemi@gmail.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=linux-kernel@vger.kernel.org \
/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).