From: Jonas Gorski <jogo@openwrt.org>
To: Florian Fainelli <florian@openwrt.org>
Cc: Joe Perches <joe@perches.com>, Daniel Walter <dwalter@google.com>,
Ralf Baechle <ralf@linux-mips.org>,
Linux-MIPS <linux-mips@linux-mips.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] ar7: replace mac address parsing
Date: Wed, 1 Apr 2015 14:17:16 +0200 [thread overview]
Message-ID: <CAOiHx==91cquJ0OAf-n40HB39HbtLw-5RrxhxtsJXbTyNgit8w@mail.gmail.com> (raw)
In-Reply-To: <CAGVrzcbgds+zHbTJWnUi48Nn1xPiEjGV7PGRmUX46da2CD+G=g@mail.gmail.com>
On Tue, Jun 24, 2014 at 9:26 PM, Florian Fainelli <florian@openwrt.org> wrote:
> 2014-06-24 8:48 GMT-07:00 Joe Perches <joe@perches.com>:
>> On Tue, 2014-06-24 at 16:39 +0100, Daniel Walter wrote:
>>> Replace sscanf() with mac_pton().
>> []
>>> diff --git a/arch/mips/ar7/platform.c b/arch/mips/ar7/platform.c
>> []
>>> @@ -307,10 +307,7 @@ static void __init cpmac_get_mac(int instance, unsigned char *dev_addr)
>>> }
>>>
>>> if (mac) {
>>> - if (sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
>>> - &dev_addr[0], &dev_addr[1],
>>> - &dev_addr[2], &dev_addr[3],
>>> - &dev_addr[4], &dev_addr[5]) != 6) {
>>> + if (!mac_pton(mac, dev_addr)) {
>>
>> There is a slight functional change with this conversion.
>>
>> mac_pton is strict about leading 0's and requires a 17 char strlen.
>
> I do not have my devices handy, but I am fairly positive the use of
> sscanf() was exactly for that, we may or may not have leading zeroes.
> I am feeling a little uncomfortable with random code changes like that
> without being actually able to test on real hardware that has a
> variety of bootloaders and environment variables.
One of my two devices has a mac address with one of the numbers being
< 16, and it uses a fixed length mac:
(psbl) printenv
...
HWA_0 00:16:B6:2A:A4:3B
Also looking at the history[1] of this code, it looks like this was
just an optimization of an earlier code which did expect 17 char len:
for (i = 0; i < 6; i++)
dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
char2hex(mac[i * 3 + 1]);
So I'm tempted to say it should not cause any issues. But my sample
size is rather small.
Regards
Jonas
[1] d16f7093b6eb4f3859856f6ee4ab504cbeeea0b9
next prev parent reply other threads:[~2015-04-01 12:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 15:39 [PATCH 1/1] ar7: replace mac address parsing Daniel Walter
2014-06-24 15:48 ` Joe Perches
2014-06-24 19:26 ` Florian Fainelli
2015-04-01 12:17 ` Jonas Gorski [this message]
2015-04-01 15:08 ` Ralf Baechle
2015-04-01 18:05 ` Joe Perches
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='CAOiHx==91cquJ0OAf-n40HB39HbtLw-5RrxhxtsJXbTyNgit8w@mail.gmail.com' \
--to=jogo@openwrt.org \
--cc=dwalter@google.com \
--cc=florian@openwrt.org \
--cc=joe@perches.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;
as well as URLs for NNTP newsgroup(s).