From: Sergei Shtylyov <sshtylyov@mvista.com>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: David Daney <ddaney@caviumnetworks.com>,
linux-mips@linux-mips.org, ralf@linux-mips.org,
devicetree-discuss@lists.ozlabs.org,
linux-kernel@vger.kernel.org,
Jeremy Kerr <jeremy.kerr@canonical.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Dan Carpenter <error27@gmail.com>,
Greg Kroah-Hartman <gregkh@suse.de>
Subject: Re: [PATCH] of: of_mdio: Fix some endianness problems.
Date: Mon, 01 Nov 2010 14:44:00 +0300 [thread overview]
Message-ID: <4CCEA800.9040500@mvista.com> (raw)
In-Reply-To: <AANLkTi=24H4RNonXu=i3CHhYqbLniDya+BKnj_evw_p6@mail.gmail.com>
Hello.
On 31-10-2010 5:54, Grant Likely wrote:
>>> In of_mdiobus_register(), the __be32 *addr variable is dereferenced.
>>> This will not work on little-endian targets. Also since it is
>>> unsigned, checking for less than zero is redundant.
>>> Fix these two issues.
>>> Signed-off-by: David Daney<ddaney@caviumnetworks.com>
>>> Cc: Grant Likely<grant.likely@secretlab.ca>
>>> Cc: Jeremy Kerr<jeremy.kerr@canonical.com>
>>> Cc: Benjamin Herrenschmidt<benh@kernel.crashing.org>
>>> Cc: Dan Carpenter<error27@gmail.com>
>>> Cc: Greg Kroah-Hartman<gregkh@suse.de>
>>> ---
>>> drivers/of/of_mdio.c | 23 ++++++++++++++---------
>>> 1 files changed, 14 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
>>> index 1fce00e..b370306 100644
>>> --- a/drivers/of/of_mdio.c
>>> +++ b/drivers/of/of_mdio.c
>>> @@ -52,27 +52,32 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>>>
>>> /* Loop over the child nodes and register a phy_device for each one */
>>> for_each_child_of_node(np, child) {
>>> - const __be32 *addr;
>>> + const __be32 *paddr;
>>> + u32 addr;
>>> int len;
>>>
>>> /* A PHY must have a reg property in the range [0-31] */
>>> - addr = of_get_property(child, "reg",&len);
>>> - if (!addr || len< sizeof(*addr) || *addr>= 32 || *addr< 0) {
>>> + paddr = of_get_property(child, "reg",&len);
>>> + if (!paddr || len< sizeof(*paddr)) {
>>> +addr_err:
>>> dev_err(&mdio->dev, "%s has invalid PHY address\n",
>>> child->full_name);
>>> continue;
>>> }
>>> + addr = be32_to_cpup(paddr);
>>> + if (addr>= 32)
>>> + goto addr_err;
>> goto's are fine for jumping to the end of a function to unwind
>> allocations, but please don't use it in this manner. The original
>> structure will actually work just fine if you do it thusly:
>> if (!paddr || len< sizeof(*paddr) ||
>> *(addr = be32_to_cpup(paddr))>= 32) {
>> dev_err(&mdio->dev, "%s has invalid PHY address\n",
>> child->full_name);
>> continue;
>> }
>> Otherwise this patch looks good. After you've reworked and retested
>> I'll pick it up for 2.6.37 (or dave will).
> Actually, I mistyped this. I think it should be:
>
> if (!paddr || len< sizeof(*paddr) ||
> (addr = be32_to_cpup(paddr))>= 32) {
This assignment would probably cause checkpatch.pl to complain...
WBR, Sergei
next prev parent reply other threads:[~2010-11-01 11:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-28 1:03 [PATCH] of: of_mdio: Fix some endianness problems David Daney
2010-10-30 6:32 ` Grant Likely
2010-10-31 2:54 ` Grant Likely
2010-11-01 11:44 ` Sergei Shtylyov [this message]
2010-11-01 14:20 ` Grant Likely
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=4CCEA800.9040500@mvista.com \
--to=sshtylyov@mvista.com \
--cc=benh@kernel.crashing.org \
--cc=ddaney@caviumnetworks.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=error27@gmail.com \
--cc=grant.likely@secretlab.ca \
--cc=gregkh@suse.de \
--cc=jeremy.kerr@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.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