From 7cc9e5030ed3d47bc1daa14506dfaeed1449fc93 Mon Sep 17 00:00:00 2001 From: Rafal Jaworowski Date: Wed, 12 Mar 2008 16:12:48 +0000 Subject: [PATCH] Improve handling U-Boot's "eth%daddr" while PowerPC metadata preparation. We're now more robust against cases of non-sorted and/or non-continuous numbering of those entries. Reviewed by: imp, marcel Approved by: cognet (mentor) --- sys/boot/powerpc/uboot/metadata.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sys/boot/powerpc/uboot/metadata.c b/sys/boot/powerpc/uboot/metadata.c index f9d9a62f344b..c4342ed133a7 100644 --- a/sys/boot/powerpc/uboot/metadata.c +++ b/sys/boot/powerpc/uboot/metadata.c @@ -267,7 +267,7 @@ md_bootinfo(struct bootinfo **addr) const char *env; void *ptr; u_int8_t tmp_addr[6]; - int i, mr_no, eth_no, size; + int i, n, mr_no, eth_no, size; if ((si = ub_get_sys_info()) == NULL) panic("can't retrieve U-Boot sysinfo"); @@ -301,15 +301,32 @@ md_bootinfo(struct bootinfo **addr) if (strncmp(env, "eth", 3) == 0 && strncmp(env + (strlen(env) - 4), "addr", 4) == 0) { + /* Extract interface number */ + i = strtol(env + 3, &end, 10); + if (end == (env + 3)) + /* 'ethaddr' means interface 0 address */ + n = 0; + else + n = i; + + if (n >= TMP_MAX_MR) { + printf("Ethernet interface number too high: %d. " + "Skipping...\n"); + continue; + } + str = ub_env_get(env); for (i = 0; i < 6; i++) { tmp_addr[i] = str ? strtol(str, &end, 16) : 0; if (str) str = (*end) ? end + 1 : end; - tmp_eth[eth_no].mac_addr[i] = tmp_addr[i]; + tmp_eth[n].mac_addr[i] = tmp_addr[i]; } - eth_no++; + + /* eth_no is 1-based number of all interfaces defined */ + if (n + 1 > eth_no) + eth_no = n + 1; } }