mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 4/5] net: eth: add name to struct eth_device
Date: Fri, 15 Jul 2016 09:23:08 +0200	[thread overview]
Message-ID: <1468567389-28169-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1468567389-28169-1-git-send-email-s.hauer@pengutronix.de>

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>
---
 include/net.h |  6 ++++++
 net/eth.c     | 12 +++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/net.h b/include/net.h
index 81118d2..8f857c8 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 499f4b0..6f8e78d 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);
 }
-- 
2.8.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-07-15  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-15  7:23 [PATCH 1/5] net: usb: use minimum timeout when polling for new packets Sascha Hauer
2016-07-15  7:23 ` [PATCH 2/5] net: eth: open correct edev in eth_check_open Sascha Hauer
2016-07-15  7:23 ` [PATCH 3/5] net: introduce for_each_netdev iterator Sascha Hauer
2016-07-15  7:23 ` Sascha Hauer [this message]
2016-07-15  7:23 ` [PATCH 5/5] net: Pass network device to net_answer_arp() Sascha Hauer

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=1468567389-28169-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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