* [PATCH 1/1] ar7: replace mac address parsing @ 2014-06-24 15:39 Daniel Walter 2014-06-24 15:48 ` Joe Perches 0 siblings, 1 reply; 6+ messages in thread From: Daniel Walter @ 2014-06-24 15:39 UTC (permalink / raw) To: Ralf Baechle; +Cc: linux-mips, linux-kernel Replace sscanf() with mac_pton(). Signed-off-by: Daniel Walter <dwalter@google.com> --- arch/mips/ar7/platform.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- diff --git a/arch/mips/ar7/platform.c b/arch/mips/ar7/platform.c index 7e2356f..653cbff 100644 --- 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)) { pr_warning("cannot parse mac address, " "using random address\n"); eth_random_addr(dev_addr); ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] ar7: replace mac address parsing 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 0 siblings, 1 reply; 6+ messages in thread From: Joe Perches @ 2014-06-24 15:48 UTC (permalink / raw) To: Daniel Walter; +Cc: Ralf Baechle, linux-mips, linux-kernel 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. 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"); ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] ar7: replace mac address parsing 2014-06-24 15:48 ` Joe Perches @ 2014-06-24 19:26 ` Florian Fainelli 2015-04-01 12:17 ` Jonas Gorski 0 siblings, 1 reply; 6+ messages in thread From: Florian Fainelli @ 2014-06-24 19:26 UTC (permalink / raw) To: Joe Perches; +Cc: Daniel Walter, Ralf Baechle, Linux-MIPS, linux-kernel 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] ar7: replace mac address parsing 2014-06-24 19:26 ` Florian Fainelli @ 2015-04-01 12:17 ` Jonas Gorski 2015-04-01 15:08 ` Ralf Baechle 2015-04-01 18:05 ` Joe Perches 0 siblings, 2 replies; 6+ messages in thread From: Jonas Gorski @ 2015-04-01 12:17 UTC (permalink / raw) To: Florian Fainelli Cc: Joe Perches, Daniel Walter, Ralf Baechle, Linux-MIPS, linux-kernel 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] ar7: replace mac address parsing 2015-04-01 12:17 ` Jonas Gorski @ 2015-04-01 15:08 ` Ralf Baechle 2015-04-01 18:05 ` Joe Perches 1 sibling, 0 replies; 6+ messages in thread From: Ralf Baechle @ 2015-04-01 15:08 UTC (permalink / raw) To: Jonas Gorski Cc: Florian Fainelli, Joe Perches, Daniel Walter, Linux-MIPS, linux-kernel On Wed, Apr 01, 2015 at 02:17:16PM +0200, Jonas Gorski wrote: > 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. 4.1 is still long enough out to test ... Ralf ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] ar7: replace mac address parsing 2015-04-01 12:17 ` Jonas Gorski 2015-04-01 15:08 ` Ralf Baechle @ 2015-04-01 18:05 ` Joe Perches 1 sibling, 0 replies; 6+ messages in thread From: Joe Perches @ 2015-04-01 18:05 UTC (permalink / raw) To: Jonas Gorski Cc: Florian Fainelli, Daniel Walter, Ralf Baechle, Linux-MIPS, linux-kernel On Wed, 2015-04-01 at 14:17 +0200, Jonas Gorski wrote: > 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. > [1] d16f7093b6eb4f3859856f6ee4ab504cbeeea0b9 Wow Jonas, a 9 month thread gestation... Given the old code and the commit comment, I'd say it was almost certainly safe and my issue with the patch resolved. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-04-01 18:05 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2015-04-01 15:08 ` Ralf Baechle 2015-04-01 18:05 ` Joe Perches
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).