[U-Boot] [PATCH 1/3] net/eth_device: keep index inside each device
Jean-Christophe PLAGNIOL-VILLARD
plagnioj at jcrosoft.com
Tue Aug 11 22:49:05 CEST 2009
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
include/net.h | 1 +
net/eth.c | 17 +++++------------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/net.h b/include/net.h
index 4a03717..2a8a12d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -93,6 +93,7 @@ enum eth_state_t {
};
struct eth_device {
+ int index;
char name[NAMESIZE];
unsigned char enetaddr[6];
int iobase;
diff --git a/net/eth.c b/net/eth.c
index 42f74da..2316a22 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -83,6 +83,7 @@ static unsigned int eth_rcv_current = 0, eth_rcv_last = 0;
#endif
static struct eth_device *eth_devices, *eth_current;
+static int nb_eth_devices = 0;
struct eth_device *eth_get_dev(void)
{
@@ -133,22 +134,12 @@ struct eth_device *eth_get_dev_by_index(int index)
int eth_get_dev_index (void)
{
- struct eth_device *dev;
- int num = 0;
-
if (!eth_devices) {
return (-1);
}
- for (dev = eth_devices; dev; dev = dev->next) {
- if (dev == eth_current)
- break;
- ++num;
- }
-
- if (dev) {
- return (num);
- }
+ if (eth_current)
+ return eth_current->index;
return (0);
}
@@ -172,6 +163,8 @@ int eth_register(struct eth_device* dev)
d->next = dev;
}
+ dev->index = nb_eth_devices;
+ nb_eth_devices++;
dev->state = ETH_STATE_INIT;
dev->next = eth_devices;
--
1.6.4
More information about the U-Boot
mailing list