From patchwork Thu Jan 27 10:49:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 537901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32B34C4332F for ; Thu, 27 Jan 2022 10:49:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239685AbiA0KtW (ORCPT ); Thu, 27 Jan 2022 05:49:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239650AbiA0KtR (ORCPT ); Thu, 27 Jan 2022 05:49:17 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37A4BC061747 for ; Thu, 27 Jan 2022 02:49:17 -0800 (PST) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nD2Kz-0007ko-3G; Thu, 27 Jan 2022 11:49:09 +0100 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nD2Kx-003lzO-RJ; Thu, 27 Jan 2022 11:49:07 +0100 From: Oleksij Rempel To: Oliver Neukum , "David S. Miller" , Jakub Kicinski , Rob Herring Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH net-next v1 4/4] usbnet: add support for label from device tree Date: Thu, 27 Jan 2022 11:49:05 +0100 Message-Id: <20220127104905.899341-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220127104905.899341-1-o.rempel@pengutronix.de> References: <20220127104905.899341-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-usb@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 --- 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 #include #include +#include /*-------------------------------------------------------------------------*/ @@ -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;