From: olof@lixom.net
To: jgarzik@pobox.com
Cc: netdev@vger.kernel.org
Subject: [patch 4/4] pasemi_mac: Fix local-mac-address parsing
Date: Sat, 12 May 2007 14:57:46 -0500 [thread overview]
Message-ID: <20070512195746.GE15137@lixom.net> (raw)
In-Reply-To: 20070512193929.193104000@localhost.localdomain
[-- Attachment #1: fix-mac-addr-parsing --]
[-- Type: text/plain, Size: 1670 bytes --]
Turns out we have an old version of firmware that stores the mac address
in 'mac-address' as a string instead of a byte array. All versions that
use local-mac-address should have it as byte array, so no need to do
string parsing for that case.
Signed-off-by: Olof Johansson <olof@lixom.net>
Index: netdev-2.6/drivers/net/pasemi_mac.c
===================================================================
--- netdev-2.6.orig/drivers/net/pasemi_mac.c
+++ netdev-2.6/drivers/net/pasemi_mac.c
@@ -85,6 +85,7 @@ static int pasemi_get_mac_addr(struct pa
{
struct pci_dev *pdev = mac->pdev;
struct device_node *dn = pci_device_to_OF_node(pdev);
+ int len;
const u8 *maddr;
u8 addr[6];
@@ -94,9 +95,17 @@ static int pasemi_get_mac_addr(struct pa
return -ENOENT;
}
- maddr = of_get_property(dn, "local-mac-address", NULL);
+ maddr = of_get_property(dn, "local-mac-address", &len);
+
+ if (maddr && len == 6) {
+ memcpy(mac->mac_addr, maddr, 6);
+ return 0;
+ }
+
+ /* Some old versions of firmware mistakenly uses mac-address
+ * (and as a string) instead of a byte array in local-mac-address.
+ */
- /* Fall back to mac-address for older firmware */
if (maddr == NULL)
maddr = of_get_property(dn, "mac-address", NULL);
@@ -106,6 +115,7 @@ static int pasemi_get_mac_addr(struct pa
return -ENOENT;
}
+
if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
&addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
dev_warn(&pdev->dev,
@@ -113,7 +123,8 @@ static int pasemi_get_mac_addr(struct pa
return -EINVAL;
}
- memcpy(mac->mac_addr, addr, sizeof(addr));
+ memcpy(mac->mac_addr, addr, 6);
+
return 0;
}
--
prev parent reply other threads:[~2007-05-12 19:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20070512193929.193104000@localhost.localdomain>
2007-05-12 19:57 ` [patch 1/4] pasemi_mac: Fix register defines olof
2007-05-15 21:44 ` Jeff Garzik
2007-05-12 19:57 ` [patch 2/4] pasemi_mac: Interrupt ack fixes olof
2007-05-12 23:01 ` [patch 2/4] [v2] " Olof Johansson
2007-05-12 19:57 ` [patch 3/4] pasemi_mac: Terminate PCI ID list olof
2007-05-12 19:57 ` olof [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070512195746.GE15137@lixom.net \
--to=olof@lixom.net \
--cc=jgarzik@pobox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).