summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-05-18 10:27:24 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-07-14 22:24:53 +0200
commit5ed70d2fa244e9d680cb2f69153fcb2ea52ea57a (patch)
tree9719c35a44551b951524b5e6f0be485e5c09eda1
parent8b3244d3a8e06d743c58324ab407e3746c4e1e84 (diff)
downloadbarebox-5ed70d2fa244e9d680cb2f69153fcb2ea52ea57a.tar.gz
barebox-5ed70d2fa244e9d680cb2f69153fcb2ea52ea57a.tar.xz
net: eth: add name to struct eth_device
Using dev_name often is not a good idea since it's a statically allocated string which gets overwritten by later calls to dev_name. Add a devname string to struct eth_device to have the name available for later use. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/net.h6
-rw-r--r--net/eth.c12
2 files changed, 13 insertions, 5 deletions
diff --git a/include/net.h b/include/net.h
index 81118d26dc..8f857c8f85 100644
--- a/include/net.h
+++ b/include/net.h
@@ -51,6 +51,7 @@ struct eth_device {
struct phy_device *phydev;
struct device_d dev;
+ char *devname;
struct device_d *parent;
char *nodepath;
@@ -65,6 +66,11 @@ struct eth_device {
#define dev_to_edev(d) container_of(d, struct eth_device, dev)
+static inline const char *eth_name(struct eth_device *edev)
+{
+ return edev->devname;
+}
+
int eth_register(struct eth_device* dev); /* Register network device */
void eth_unregister(struct eth_device* dev); /* Unregister network device */
int eth_set_ethaddr(struct eth_device *edev, const char *ethaddr);
diff --git a/net/eth.c b/net/eth.c
index 499f4b04da..6f8e78d8d3 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -164,7 +164,7 @@ struct eth_device *eth_get_byname(const char *ethname)
struct eth_device *edev;
for_each_netdev(edev) {
- if (!strcmp(ethname, dev_name(&edev->dev)))
+ if (!strcmp(ethname, eth_name(edev)))
return edev;
}
return NULL;
@@ -174,17 +174,15 @@ struct eth_device *eth_get_byname(const char *ethname)
int eth_complete(struct string_list *sl, char *instr)
{
struct eth_device *edev;
- const char *devname;
int len;
len = strlen(instr);
for_each_netdev(edev) {
- devname = dev_name(&edev->dev);
- if (strncmp(instr, devname, len))
+ if (strncmp(instr, eth_name(edev), len))
continue;
- string_list_add_asprintf(sl, "%s ", devname);
+ string_list_add_asprintf(sl, "%s ", eth_name(edev));
}
return COMPLETE_CONTINUE;
}
@@ -378,6 +376,8 @@ int eth_register(struct eth_device *edev)
if (ret)
return ret;
+ edev->devname = xstrdup(dev_name(&edev->dev));
+
dev_add_param_ip(dev, "ipaddr", NULL, NULL, &edev->ipaddr, edev);
dev_add_param_ip(dev, "serverip", NULL, NULL, &edev->serverip, edev);
dev_add_param_ip(dev, "gateway", NULL, NULL, &edev->gateway, edev);
@@ -424,6 +424,8 @@ void eth_unregister(struct eth_device *edev)
if (IS_ENABLED(CONFIG_OFDEVICE))
free(edev->nodepath);
+ free(edev->devname);
+
unregister_device(&edev->dev);
list_del(&edev->list);
}