linux-mips
[Top] [All Lists]

Re: [PATCH 1/1] ar7: replace mac address parsing

To: Joe Perches <joe@perches.com>
Subject: Re: [PATCH 1/1] ar7: replace mac address parsing
From: Florian Fainelli <florian@openwrt.org>
Date: Tue, 24 Jun 2014 12:26:15 -0700
Cc: 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>
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=F8SPeHRnJNvo6u5tuygkh1Tft/1e3liItK//wm0/x70=; b=l1rnD2KZu5Ca7hpa1GiaydlK0ocd02vv+bCoyIpfoW73X8vjLpb0s5SB861qQAP4jR 0srmXPhY465si1MkOnPkqlKRIfPjhZO8M6fMCQGPyC60aE06Tgtqs6Tz9327ekRk9UES O4VebzwnvR9CK7LTq52xxv3/1ivNyjgzwKbuqKaabONuWxt0rektaULgeNQDpP4UNaIm 9cSTzpMKcurbSNv+W2wdeB4lqBjec1pQSvLD8yxRxuaZ3TM7U+NdrWK9rzOdDvMLvjTr 4KfG+B725DmSvlPpDbtBVHFOI/QATlGbRb4LPNSdJ9pvf5zMMcPsykoUXiao8EmQI5Fg 0fEQ==
In-reply-to: <1403624918.29061.16.camel@joe-AO725>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20140624153959.GA19564@google.com> <1403624918.29061.16.camel@joe-AO725>
Sender: linux-mips-bounce@linux-mips.org
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.

>
> sscanf will accept 0:1:2:3:4:5, mac_pton will not.
>
>>                       pr_warning("cannot parse mac address, "
>>                                       "using random address\n");
>
> could be coalesced and pr_warn
>
>                         pr_warn("cannot parse mac address - using random 
> address\n");
>
>
>



-- 
Florian

<Prev in Thread] Current Thread [Next in Thread>