Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753151AbbDASF5 (ORCPT ); Wed, 1 Apr 2015 14:05:57 -0400 Received: from smtprelay0227.hostedemail.com ([216.40.44.227]:46481 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752799AbbDASF4 (ORCPT ); Wed, 1 Apr 2015 14:05:56 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1801:2194:2199:2393:2553:2559:2562:2689:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3871:3872:3874:4321:4605:5007:6261:7903:8603:9036:9121:10004:10400:10848:11026:11232:11658:11914:12043:12050:12438:12517:12519:12555:12663:12740:13161:13229:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: dogs38_50825c1206c2f X-Filterd-Recvd-Size: 3340 Message-ID: <1427911550.31790.56.camel@perches.com> Subject: Re: [PATCH 1/1] ar7: replace mac address parsing From: Joe Perches To: Jonas Gorski Cc: Florian Fainelli , Daniel Walter , Ralf Baechle , Linux-MIPS , "linux-kernel@vger.kernel.org" Date: Wed, 01 Apr 2015 11:05:50 -0700 In-Reply-To: References: <20140624153959.GA19564@google.com> <1403624918.29061.16.camel@joe-AO725> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.10-0ubuntu1~14.10.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2391 Lines: 59 On Wed, 2015-04-01 at 14:17 +0200, Jonas Gorski wrote: > On Tue, Jun 24, 2014 at 9:26 PM, Florian Fainelli wrote: > > 2014-06-24 8:48 GMT-07:00 Joe Perches : > >> 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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/