From patchwork Thu Nov 24 09:49:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Priit Laes X-Patchwork-Id: 127460 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4D0CB1007DD for ; Thu, 24 Nov 2011 20:54:34 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RTVy2-0006Ez-Dp; Thu, 24 Nov 2011 09:51:42 +0000 Received: from bombadil.infradead.org ([2001:4830:2446:ff00:4687:fcff:fea6:5117]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RTVxz-0006Eu-62 for linux-arm-kernel@merlin.infradead.org; Thu, 24 Nov 2011 09:51:39 +0000 Received: from gn237.zone.eu ([217.146.67.237]) by bombadil.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RTVxx-0003dH-2X for linux-arm-kernel@lists.infradead.org; Thu, 24 Nov 2011 09:51:38 +0000 Received: from wow (149-44-131-46.internet.emt.ee [46.131.44.149]) (Authenticated sender: plaes@plaes.org) by gn237.zone.eu (Postfix) with ESMTPSA id A963FE4E96CA; Thu, 24 Nov 2011 11:50:55 +0200 (EET) Received: by wow (sSMTP sendmail emulation); Thu, 24 Nov 2011 11:49:33 +0200 From: plaes@plaes.org Subject: Re: [PATCH] ARM: mach-orion5x: Use hex2bin that is present in kernel lib To: Lennert Buytenhek In-Reply-To: <20111124064018.GD795@wantstofly.org> References: <1322058417.2472.9.camel@localhost.localdomain> <20111124064018.GD795@wantstofly.org> Date: Thu, 24 Nov 2011 11:49:33 +0200 Message-ID: <1322128173.31424.12.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20111124_045137_415669_6CBA89CC X-CRM114-Status: GOOD ( 20.25 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-arm-kernel@lists.infradead.org, nico@fluxnic.net X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org Ühel kenal päeval, N, 2011-11-24 kell 07:40, kirjutas Lennert Buytenhek: > On Wed, Nov 23, 2011 at 04:26:57PM +0200, plaes@plaes.org wrote: > [...] > > > > [...] > > > > for (i = 0; i < 6; i++) { > > - int byte; > > - > > - byte = dns323_parse_hex_byte(mac_page + (i * 3)); > > - if (byte < 0) { > > + if (hex2bin(addr[i], mac_page + (i * 3), 2)) > > goto error_fail; > > I don't think that this does what you think it does... Indeed. I assume that it didn't even compile. I have fixed the two issues I found in the previous patch and tweaked the printk output for TS-x09. Run-tested with similar code on x86 so now I'm confident enough to sign it off ;) Päikest, Priit Laes ;) From 4bc5154a590062914511edd819a4b715abfec748 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Wed, 23 Nov 2011 16:11:04 +0200 Subject: [PATCH] ARM: mach-orion5x: Use hex2bin that is present in kernel lib Signed-off-by: Priit Laes --- arch/arm/mach-orion5x/dns323-setup.c | 39 +--------------------------------- arch/arm/mach-orion5x/tsx09-common.c | 36 +----------------------------- 2 files changed, 3 insertions(+), 72 deletions(-) diff --git a/arch/arm/mach-orion5x/dns323-setup.c b/arch/arm/mach-orion5x/dns323-setup.c index 343f60e..27ad32a 100644 --- a/arch/arm/mach-orion5x/dns323-setup.c +++ b/arch/arm/mach-orion5x/dns323-setup.c @@ -172,37 +172,6 @@ static struct mv643xx_eth_platform_data dns323_eth_data = { .phy_addr = MV643XX_ETH_PHY_ADDR(8), }; -/* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these - * functions be kept somewhere? - */ -static int __init dns323_parse_hex_nibble(char n) -{ - if (n >= '0' && n <= '9') - return n - '0'; - - if (n >= 'A' && n <= 'F') - return n - 'A' + 10; - - if (n >= 'a' && n <= 'f') - return n - 'a' + 10; - - return -1; -} - -static int __init dns323_parse_hex_byte(const char *b) -{ - int hi; - int lo; - - hi = dns323_parse_hex_nibble(b[0]); - lo = dns323_parse_hex_nibble(b[1]); - - if (hi < 0 || lo < 0) - return -1; - - return (hi << 4) | lo; -} - static int __init dns323_read_mac_addr(void) { u_int8_t addr[6]; @@ -224,14 +193,8 @@ static int __init dns323_read_mac_addr(void) } for (i = 0; i < 6; i++) { - int byte; - - byte = dns323_parse_hex_byte(mac_page + (i * 3)); - if (byte < 0) { + if (hex2bin(&addr[i], mac_page + (i * 3), 1)) goto error_fail; - } - - addr[i] = byte; } iounmap(mac_page); diff --git a/arch/arm/mach-orion5x/tsx09-common.c b/arch/arm/mach-orion5x/tsx09-common.c index c9abb8f..5f94319 100644 --- a/arch/arm/mach-orion5x/tsx09-common.c +++ b/arch/arm/mach-orion5x/tsx09-common.c @@ -52,55 +52,23 @@ struct mv643xx_eth_platform_data qnap_tsx09_eth_data = { .phy_addr = MV643XX_ETH_PHY_ADDR(8), }; -static int __init qnap_tsx09_parse_hex_nibble(char n) -{ - if (n >= '0' && n <= '9') - return n - '0'; - - if (n >= 'A' && n <= 'F') - return n - 'A' + 10; - - if (n >= 'a' && n <= 'f') - return n - 'a' + 10; - - return -1; -} - -static int __init qnap_tsx09_parse_hex_byte(const char *b) -{ - int hi; - int lo; - - hi = qnap_tsx09_parse_hex_nibble(b[0]); - lo = qnap_tsx09_parse_hex_nibble(b[1]); - - if (hi < 0 || lo < 0) - return -1; - - return (hi << 4) | lo; -} - static int __init qnap_tsx09_check_mac_addr(const char *addr_str) { u_int8_t addr[6]; int i; for (i = 0; i < 6; i++) { - int byte; - /* * Enforce "xx:xx:xx:xx:xx:xx\n" format. */ if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n')) return -1; - byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3)); - if (byte < 0) + if (hex2bin(&addr[i], addr_str + (i * 3), 1)) return -1; - addr[i] = byte; } - printk(KERN_INFO "tsx09: found ethernet mac address "); + printk(KERN_INFO "TS-x09: Found ethernet MAC address: "); for (i = 0; i < 6; i++) printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n"); -- 1.7.8.rc3