linux-mips
[Top] [All Lists]

[PATCH v3] arch/mips/rb532: replace mac_addr parsing

To: Ralf Baechle <ralf@linux-mips.org>
Subject: [PATCH v3] arch/mips/rb532: replace mac_addr parsing
From: Daniel Walter <dwalter@google.com>
Date: Tue, 24 Jun 2014 12:14:26 +0100
Cc: james.hogan@imgtec.com, linux-mips@linux-mips.org, linux-kernel@vger.kernel.org
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=8SUeu1cfmDvf4Hg+oGBs6JNatAPgFvO1jFdfk0+KZfo=; b=KWmdwnGBY0U+XMnXxF3wlymVrpcm16AGdZxciU0SMeU9K1X7yq+742dqY/ShcPve2r Q16UtbD7M66zUGN1QP3C0Knvw5U68u0hE9HwMJTqpwzH3UPFOCYGQHKz8wodGwztCnXv fjuo2rysYy6bl1l6sprNgNJ+8qCw3X2NQA3Xkx8JhA0m/J0ELQGckdYX1rnNWqW92QAb /TxpwzIyV0nTCSZeIsOVow1uJF0Ohl9blgGDJjR31sr0SpANXJAo5gFOgljlkZby+Fug /QNIIWuiHSrw0ShtZgqJpPRbAgbWZi+WrZz8uAaCVBLwXql+LN2bu3860246jr05i7ES QOHQ==
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
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.21 (2010-09-15)
Replace parse_mac_addr with mac_pton().


Signed-off-by: Daniel Walter <dwalter@google.com>
---
Changes since v2
  Use mac_pton() instead of sscanf()
  added error handling in case could not be parsed
---
Patch applies against current linux-git
---
 arch/mips/rb532/devices.c | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)
---
diff --git a/arch/mips/rb532/devices.c b/arch/mips/rb532/devices.c
index 3af00b2..03a4cdc 100644
--- a/arch/mips/rb532/devices.c
+++ b/arch/mips/rb532/devices.c
@@ -250,28 +250,6 @@ static struct platform_device *rb532_devs[] = {
        &rb532_wdt
 };
 
-static void __init parse_mac_addr(char *macstr)
-{
-       int i, h, l;
-
-       for (i = 0; i < 6; i++) {
-               if (i != 5 && *(macstr + 2) != ':')
-                       return;
-
-               h = hex_to_bin(*macstr++);
-               if (h == -1)
-                       return;
-
-               l = hex_to_bin(*macstr++);
-               if (l == -1)
-                       return;
-
-               macstr++;
-               korina_dev0_data.mac[i] = (h << 4) + l;
-       }
-}
-
-
 /* NAND definitions */
 #define NAND_CHIP_DELAY 25
 
@@ -333,7 +311,10 @@ static int __init plat_setup_devices(void)
 static int __init setup_kmac(char *s)
 {
        printk(KERN_INFO "korina mac = %s\n", s);
-       parse_mac_addr(s);
+       if (!mac_pton(s, korina_dev0_data.mac)) {
+               printk(KERN_ERR "Invalid mac\n");
+               return -EINVAL;
+       }
        return 0;
 }
 

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