diff mbox

[U-Boot,02/14] net: cosmetic: Make the MAC address string less magical

Message ID 20161125153032.14617-3-oliver@schinagl.nl
State Accepted
Commit 9f455bcb34fcab31b0eb8eec5702105c8d4bde18
Delegated to: Joe Hershberger
Headers show

Commit Message

Olliver Schinagl Nov. 25, 2016, 3:30 p.m. UTC
In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
---
 include/net.h    | 5 +++++
 net/eth_common.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Joe Hershberger Nov. 30, 2016, 7:15 p.m. UTC | #1
On Fri, Nov 25, 2016 at 9:30 AM, Olliver Schinagl <oliver@schinagl.nl> wrote:
> In u-boot printf has been extended with the %pM formatter to allow
> printing of MAC addresses. However buffers that want to store a MAC
> address cannot safely get the size. Add a define for this case so the
> string of a MAC address can be reliably obtained.
>
> Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger Feb. 9, 2017, 4:26 p.m. UTC | #2
Hi oliver@schinagl.nl,

https://patchwork.ozlabs.org/patch/699273/ was applied to u-boot-net.git.

Thanks!
-Joe
diff mbox

Patch

diff --git a/include/net.h b/include/net.h
index 8137cf3..af0558d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -40,6 +40,11 @@ 
 
 /* ARP hardware address length */
 #define ARP_HLEN 6
+/*
+ * The size of a MAC address in string form, each digit requires two chars
+ * and five separator characters to form '00:00:00:00:00:00'.
+ */
+#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1)
 
 /* IPv4 addresses are always 32 bits in size */
 struct in_addr {
diff --git a/net/eth_common.c b/net/eth_common.c
index 2880901..e9d3c66 100644
--- a/net/eth_common.c
+++ b/net/eth_common.c
@@ -32,7 +32,7 @@  int eth_getenv_enetaddr(const char *name, uchar *enetaddr)
 
 int eth_setenv_enetaddr(const char *name, const uchar *enetaddr)
 {
-	char buf[20];
+	char buf[ARP_HLEN_ASCII + 1];
 
 	sprintf(buf, "%pM", enetaddr);