From: "Pali Rohár" <pali@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Rob Herring" <robh+dt@kernel.org>,
"Andrew Lunn" <andrew@lunn.ch>,
"Russell King" <linux@armlinux.org.uk>,
"Marek Behún" <kabel@kernel.org>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] of: net: Add helper function of_get_ethdev_label()
Date: Fri, 7 Jan 2022 17:12:21 +0100 [thread overview]
Message-ID: <20220107161222.14043-1-pali@kernel.org> (raw)
Adds a new helper function of_get_ethdev_label() which sets initial name of
specified netdev interface based on DT "label" property. It is same what is
doing DSA function dsa_port_parse_of() for DSA ports.
This helper function can be useful for drivers to make consistency between
DSA and netdev interface names.
Signed-off-by: Pali Rohár <pali@kernel.org>
---
include/linux/of_net.h | 6 ++++++
net/core/of_net.c | 15 +++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/of_net.h b/include/linux/of_net.h
index 0484b613ca64..532d88127b42 100644
--- a/include/linux/of_net.h
+++ b/include/linux/of_net.h
@@ -15,6 +15,7 @@ struct net_device;
extern int of_get_phy_mode(struct device_node *np, phy_interface_t *interface);
extern int of_get_mac_address(struct device_node *np, u8 *mac);
int of_get_ethdev_address(struct device_node *np, struct net_device *dev);
+int of_get_ethdev_label(struct device_node *np, struct net_device *dev);
extern struct net_device *of_find_net_device_by_node(struct device_node *np);
#else
static inline int of_get_phy_mode(struct device_node *np,
@@ -33,6 +34,11 @@ static inline int of_get_ethdev_address(struct device_node *np, struct net_devic
return -ENODEV;
}
+static inline int of_get_ethdev_label(struct device_node *np, struct net_device *dev)
+{
+ return -ENODEV;
+}
+
static inline struct net_device *of_find_net_device_by_node(struct device_node *np)
{
return NULL;
diff --git a/net/core/of_net.c b/net/core/of_net.c
index f1a9bf7578e7..18fc99c42461 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -168,3 +168,18 @@ int of_get_ethdev_address(struct device_node *np, struct net_device *dev)
return ret;
}
EXPORT_SYMBOL(of_get_ethdev_address);
+
+int of_get_ethdev_label(struct device_node *np, struct net_device *dev)
+{
+ const char *name = of_get_property(np, "label", NULL);
+
+ if (!name)
+ return -ENOENT;
+
+ if (strlen(name) >= sizeof(dev->name))
+ return -ENAMETOOLONG;
+
+ strcpy(dev->name, name);
+ return 0;
+}
+EXPORT_SYMBOL(of_get_ethdev_label);
--
2.20.1
next reply other threads:[~2022-01-07 16:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-07 16:12 Pali Rohár [this message]
2022-01-07 16:12 ` [PATCH 2/2] of: net: Call of_get_ethdev_label() in all DT based net drivers Pali Rohár
2022-01-07 16:29 ` [PATCH 1/2] of: net: Add helper function of_get_ethdev_label() Russell King (Oracle)
2022-01-07 16:55 ` Andrew Lunn
2022-01-13 18:27 ` Pali Rohár
2022-02-08 11:00 ` Pali Rohár
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=20220107161222.14043-1-pali@kernel.org \
--to=pali@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=kabel@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=robh+dt@kernel.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;
as well as URLs for NNTP newsgroup(s).