From: Lee Jones <lee.jones@linaro.org>
To: Stefan Agner <stefan@agner.ch>
Cc: Stephen Warren <swarren@wwwdotorg.org>,
thierry.reding@gmail.com, dev@lynxeye.de, lgirdwood@gmail.com,
broonie@kernel.org, kai.poggensee@avionic-design.de,
sameo@linux.intel.com, linux-tegra@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/3] mfd: tps6586x: add version detection
Date: Fri, 6 Dec 2013 08:44:53 +0000 [thread overview]
Message-ID: <20131206084453.GB13093@lee--X1> (raw)
In-Reply-To: <ac11b85d05765b3b68eff8c27041e965@agner.ch>
> >> <snip>
> >>>> @@ -493,13 +527,12 @@ static int tps6586x_i2c_probe(struct i2c_client *client,
> >>>> return -EIO;
> >>>> }
> >>>>
> >>>> - dev_info(&client->dev, "VERSIONCRC is %02x\n", ret);
> >>>> -
> >>>> tps6586x = devm_kzalloc(&client->dev, sizeof(*tps6586x), GFP_KERNEL);
> >>>> - if (tps6586x == NULL) {
> >>>> - dev_err(&client->dev, "memory for tps6586x alloc failed\n");
> >>>> + if (!tps6586x)
> >>>> return -ENOMEM;
> >>>> - }
> >>>> +
> >>>> + tps6586x->version = ret;
> >>>
> >>> I have to say, I dislike this version of the patch. Separating the
> >>> reading of the version register from the assignment to tps6586x->version
> >>> doesn't make any sense, especially given that the version value is
> >>> stored in a variable named "ret"; that name isn't remotely related to
> >>> what's stored there. What if someone comes along later and adds more
> >>> code that assigns to ret between where it's repurposed for the version
> >>> value and where it's assigned to tps6586x->version? It'd be extremely
> >>> difficult for a patch reviewer to spot that given the limited context in
> >>> a diff, and quite non-obvious to the person changing the code too..
> >>
> >> The value comes from the return value of i2c_smbus_read_byte_data. If
> >> the value is below zero its an EIO error.
> >>
> >> I could add a variable "version", but for me it felt strange because we
> >> check if version is below zero. This feels like its a wrong version
> >> rather than a transmit error. So I would prefer ret over version. But I
> >> agree, when one just reads the patch, its not obvious what exactly
> >> happens.
> >
> > In my opinion, using a variable named "version" here would be
> > preferable. Testing that against <0 is just the way the I2C API works,
> > so the same argument could be applied to any I2C access.
So, FWIW I agree with Stephen and have done from the start. Please
see my original comment from the first submission:
> > ret = i2c_smbus_read_byte_data(client, TPS6586X_VERSIONCRC);
> If you're going to do this, please change 'ret' to 'version'.
> Hm, I try the empiric way:
>
> $ grep -r -e i2c_smbus_read_byte_data | grep "ret =" | wc -l
> 139
> $ grep -r -e i2c_smbus_read_byte_data | grep "version =" | wc -l
> 3
>
> Ok, thats not fair at all, version is usage specific whilst ret is not.
>
> $ grep -r -e i2c_smbus_read_byte_data | grep " = " | wc -l
> 703
I not really that worried about what everyone else does. I'm more
concerned with doing what we deem to be the correct thing here.
> On the other hand is the additional variable. But I think the compiler
> will optimize that anyway, so this might not be an argument at all :-)
>
> I see your point... Should I create another patch revision? Lee, is the
> patch already merged?
It isn't. Please submit another version as Stephen requests.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
next prev parent reply other threads:[~2013-12-06 8:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-03 22:18 [PATCH v4 0/3] regulator: tps6586x: add version detection and voltage tables Stefan Agner
2013-12-03 22:18 ` [PATCH v4 1/3] mfd: tps6586x: add version detection Stefan Agner
2013-12-04 8:10 ` Lee Jones
2013-12-04 8:40 ` Stefan Agner
2013-12-04 10:07 ` Lee Jones
2013-12-04 11:38 ` Stefan Agner
2013-12-04 11:48 ` Lee Jones
2013-12-04 11:49 ` Mark Brown
2013-12-04 11:58 ` Lee Jones
2013-12-05 17:06 ` Stephen Warren
2013-12-05 17:43 ` Stefan Agner
2013-12-05 17:40 ` Stephen Warren
2013-12-05 22:56 ` Stefan Agner
2013-12-06 8:44 ` Lee Jones [this message]
2013-12-03 22:18 ` [PATCH v4 2/3] regulator: tps6586x: add and use correct voltage table Stefan Agner
2013-12-04 9:48 ` Thierry Reding
2013-12-04 12:14 ` Mark Brown
2013-12-04 14:17 ` Stefan Agner
2013-12-04 14:29 ` Mark Brown
2013-12-04 14:40 ` Lee Jones
2013-12-05 17:10 ` Stephen Warren
2013-12-03 22:18 ` [PATCH v4 3/3] ARM: tegra: correct Colibri T20 regulator settings Stefan Agner
2013-12-04 11:52 ` Lucas Stach
2013-12-05 17:12 ` Stephen Warren
2013-12-05 17:33 ` Stefan Agner
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=20131206084453.GB13093@lee--X1 \
--to=lee.jones@linaro.org \
--cc=broonie@kernel.org \
--cc=dev@lynxeye.de \
--cc=kai.poggensee@avionic-design.de \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=sameo@linux.intel.com \
--cc=stefan@agner.ch \
--cc=swarren@wwwdotorg.org \
--cc=thierry.reding@gmail.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