* [PATCH] MIPS: AR7: rewrite of cpmac_get_mac()
@ 2010-07-05 20:11 Alexander Clouter
2010-07-06 9:39 ` Ralf Baechle
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Clouter @ 2010-07-05 20:11 UTC (permalink / raw)
To: linux-mips; +Cc: florian
Shamelessly stealing wisdom from pasemi_mac.c, I found char2hex() could
be replaced with a single call to sscanf(), looks cleaner to me at
least. The result is 100 bytes trimmed off the size of a compiled
cpmac_get_mac() and as an extra bonus it grumbles and gracefully fails
over to using random_ether_addr() when an attempt to parse an invalid
MAC address is made.
Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
---
arch/mips/ar7/platform.c | 42 +++++++++++++++---------------------------
1 files changed, 15 insertions(+), 27 deletions(-)
diff --git a/arch/mips/ar7/platform.c b/arch/mips/ar7/platform.c
index 8f31d1d..0da5b2b 100644
--- a/arch/mips/ar7/platform.c
+++ b/arch/mips/ar7/platform.c
@@ -292,40 +292,28 @@ static struct platform_device cpmac_high = {
.num_resources = ARRAY_SIZE(cpmac_high_res),
};
-static inline unsigned char char2hex(char h)
+static void __init cpmac_get_mac(int instance, unsigned char *dev_addr)
{
- switch (h) {
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- return h - '0';
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- return h - 'A' + 10;
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- return h - 'a' + 10;
- default:
- return 0;
- }
-}
-
-static void cpmac_get_mac(int instance, unsigned char *dev_addr)
-{
- int i;
- char name[5], default_mac[ETH_ALEN], *mac;
+ char name[5], *mac;
- mac = NULL;
sprintf(name, "mac%c", 'a' + instance);
mac = prom_getenv(name);
- if (!mac) {
+ if (!mac && instance) {
sprintf(name, "mac%c", 'a');
mac = prom_getenv(name);
}
- if (!mac) {
- random_ether_addr(default_mac);
- mac = default_mac;
- }
- for (i = 0; i < 6; i++)
- dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
- char2hex(mac[i * 3 + 1]);
+
+ 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) {
+ pr_warning("cannot parse mac address, "
+ "using random address\n");
+ random_ether_addr(dev_addr);
+ }
+ } else
+ random_ether_addr(dev_addr);
}
/*****************************************************************************
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] MIPS: AR7: rewrite of cpmac_get_mac()
2010-07-05 20:11 [PATCH] MIPS: AR7: rewrite of cpmac_get_mac() Alexander Clouter
@ 2010-07-06 9:39 ` Ralf Baechle
0 siblings, 0 replies; 2+ messages in thread
From: Ralf Baechle @ 2010-07-06 9:39 UTC (permalink / raw)
To: Alexander Clouter; +Cc: linux-mips, florian
Thanks, queued for 2.6.36.
Ralf
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-07-06 9:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-05 20:11 [PATCH] MIPS: AR7: rewrite of cpmac_get_mac() Alexander Clouter
2010-07-06 9:39 ` Ralf Baechle
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.