Similar to the option to set a netdev name in device tree for switch ports by using the property "label" in the DSA framework, this patch adds this functionality to the usbnet infrastructure. This will help to name the interfaces properly throughout supported devices. This provides stable interface names which are useful especially in embedded use cases. Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx> --- drivers/net/usb/usbnet.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 9a6450f796dc..3fdca0cfda88 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -33,6 +33,7 @@ #include <linux/slab.h> #include <linux/kernel.h> #include <linux/pm_runtime.h> +#include <linux/of.h> /*-------------------------------------------------------------------------*/ @@ -1762,6 +1763,20 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) if ((dev->driver_info->flags & FLAG_WWAN) != 0) strscpy(net->name, "wwan%d", sizeof(net->name)); + if (IS_ENABLED(CONFIG_OF)) { + const char *label = NULL; + + /* try reading label from device tree node */ + if (xdev->dev.of_node) + label = of_get_property(xdev->dev.of_node, + "label", NULL); + if (label) { + strscpy(net->name, label, sizeof(net->name)); + dev_info(&udev->dev, "netdev name from dt: %s\n", + net->name); + } + } + /* devices that cannot do ARP */ if ((dev->driver_info->flags & FLAG_NOARP) != 0) net->flags |= IFF_NOARP; -- 2.30.2