From patchwork Tue Mar 7 20:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 13164666 X-Patchwork-Delegate: kuba@kernel.org 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 B24ABC6FA99 for ; Tue, 7 Mar 2023 20:05:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjCGUFS (ORCPT ); Tue, 7 Mar 2023 15:05:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233003AbjCGUFP (ORCPT ); Tue, 7 Mar 2023 15:05:15 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 171B7302B7 for ; Tue, 7 Mar 2023 12:05:13 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id r5so15795627qtp.4 for ; Tue, 07 Mar 2023 12:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678219512; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4ZfEA88sr4Yu5DcAlEC64/VwnZCJ3mjOQU7Q9Ivctb0=; b=BSwqMzItvlqe/iVQBBtJ9RwZ4sy2LK/I1frRYtG6DXTUp6y1zwZphye+mtqLC2DHnl BEFiKhK4/Qau6K2hl9exI17mQr3kyO1Sc+Zky/Kjd6NcN64fhM78HLnKg7cOv1si4sIf 1sefZw8zp+rbmwE2wLAgqzJ3YnTRYk/Z2O+XY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678219512; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4ZfEA88sr4Yu5DcAlEC64/VwnZCJ3mjOQU7Q9Ivctb0=; b=mI5TMykQ74gT+gpWlOmNFUnQkfJS54gyffq2uvJaGahf93rzx9zJgvc42NvUFLHVcF Gucuhn+Th4xmqIK/2WAWDahXpkqVfgpQHNNAF0LEC+5IpXJ3+3S0tJttFTnV4GW/qrUC QX8Q+XF8WWFFGfB3kmVAZOWWIrmdH4Y6D0IZxMJAf9mslNr9qhZHEI8YlQVyF4GWTD4s /LSRfKx7d5mDpqCsXe6AuV/5gW0EHQo7SilPDyYnWHOovZ3GDFOSFM9cUGTz4nnmvRpv b0wNF5qARr/eyn1uYsvskX3QclT4FSVnV/NHsMpEnYZB4EZAV5mQTVzP5wgiiCT0lSOz y6rA== X-Gm-Message-State: AO0yUKWTW41D0stNHd85C6+b95+neOkQCCBvh4VnBCBp8jgkdEgcT9qe CvZUYgbiCyHX0G3VF1ELVuyNsQ== X-Google-Smtp-Source: AK7set/LzltnJwkKk2I5YL0RjDxBPPpKoKlkTH6bmZiO9KVRgPUTVxI0lcbYew+xriKuDHwcVId4GQ== X-Received: by 2002:a05:622a:1992:b0:3bf:e408:6c91 with SMTP id u18-20020a05622a199200b003bfe4086c91mr27739627qtc.51.1678219512180; Tue, 07 Mar 2023 12:05:12 -0800 (PST) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id b3-20020ac85bc3000000b003bfb820f17csm10451542qtb.63.2023.03.07.12.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 12:05:11 -0800 (PST) From: Grant Grundler To: Oleksij Rempel , Pavel Skripkin , Lukas Wunner Cc: Eizan Miyamoto , Jakub Kicinski , netdev , "David S . Miller" , LKML , Grant Grundler , Anton Lundin Subject: [PATCHv2 1/2] TEST:net: asix: fix modprobe "sysfs: cannot create duplicate filename" Date: Tue, 7 Mar 2023 12:05:01 -0800 Message-Id: <20230307200502.2263655-1-grundler@chromium.org> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org "modprobe asix ; rmmod asix ; modprobe asix" fails with: sysfs: cannot create duplicate filename \ '/devices/virtual/mdio_bus/usb-003:004' Issue was originally reported by Anton Lundin on 2022-06-22 14:16 UTC: https://lore.kernel.org/netdev/20220623063649.GD23685@pengutronix.de/T/ Chrome OS team hit the same issue in Feb, 2023 when trying to find work arounds for other issues with AX88172 devices. The use of devm_mdiobus_register() with usbnet devices results in the MDIO data being associated with the USB device. When the asix driver is unloaded, the USB device continues to exist and the corresponding "mdiobus_unregister()" is NOT called until the USB device is unplugged or unauthorized. So the next "modprobe asix" will fail because the MDIO phy sysfs attributes still exist. The 'easy' (from a design PoV) fix is to use the non-devm variants of mdiobus_* functions and explicitly manage this use in the asix_bind and asix_unbind function calls. I've not explored trying to fix usbnet initialization so devm_* stuff will work. Fixes: e532a096be0e5 ("net: usb: asix: ax88772: add phylib support") Reported-by: Anton Lundin Tested-by: Eizan Miyamoto Signed-off-by: Grant Grundler --- drivers/net/usb/asix_devices.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) V2: moved mdiobus_get_phy() call back into ax88772_init_phy() Lukas Wunner is entirely correct this patch is much easier to backport without this patch hunk. Added "Fixes:" tag per request from Florian Fainelli diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c index 30e87389aefa1..21845b88a64b9 100644 --- a/drivers/net/usb/asix_devices.c +++ b/drivers/net/usb/asix_devices.c @@ -640,8 +640,9 @@ static int asix_resume(struct usb_interface *intf) static int ax88772_init_mdio(struct usbnet *dev) { struct asix_common_private *priv = dev->driver_priv; + int ret; - priv->mdio = devm_mdiobus_alloc(&dev->udev->dev); + priv->mdio = mdiobus_alloc(); if (!priv->mdio) return -ENOMEM; @@ -653,7 +654,20 @@ static int ax88772_init_mdio(struct usbnet *dev) snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev->devnum); - return devm_mdiobus_register(&dev->udev->dev, priv->mdio); + ret = mdiobus_register(priv->mdio); + if (ret) { + netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret); + mdiobus_free(priv->mdio); + priv->mdio = NULL; + } + + return ret; +} + +static void ax88772_mdio_unregister(struct asix_common_private *priv) +{ + mdiobus_unregister(priv->mdio); + mdiobus_free(priv->mdio); } static int ax88772_init_phy(struct usbnet *dev) @@ -664,6 +678,7 @@ static int ax88772_init_phy(struct usbnet *dev) priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr); if (!priv->phydev) { netdev_err(dev->net, "Could not find PHY\n"); + ax88772_mdio_unregister(priv); return -ENODEV; } @@ -805,6 +820,7 @@ static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf) struct asix_common_private *priv = dev->driver_priv; phy_disconnect(priv->phydev); + ax88772_mdio_unregister(priv); asix_rx_fixup_common_free(dev->driver_priv); } From patchwork Tue Mar 7 20:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 13164667 X-Patchwork-Delegate: kuba@kernel.org 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 D56D6C6FD1E for ; Tue, 7 Mar 2023 20:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230144AbjCGUFU (ORCPT ); Tue, 7 Mar 2023 15:05:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233026AbjCGUFP (ORCPT ); Tue, 7 Mar 2023 15:05:15 -0500 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E43C38B53 for ; Tue, 7 Mar 2023 12:05:14 -0800 (PST) Received: by mail-qt1-x82d.google.com with SMTP id c19so15723252qtn.13 for ; Tue, 07 Mar 2023 12:05:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678219513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2lleS4LGwxzhnZ1C+1osdQPnYcQbqHxuWA/mdvIracQ=; b=Qm21SdwronVXhihM3Y9UYgYSgpdkOE6i8Y4epRmOjjzPEqN+1JYtV3eVUpneAvRAL7 j4ufpRX6VXYTrQaeTD0/vLIlECRKjf0P4o5ZJL097xlLteLM2gaHq309YlRtqaN0bcEG 6iQGhu55T2xkbmg7CH18KPH4nn56+yHCLL86I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678219513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2lleS4LGwxzhnZ1C+1osdQPnYcQbqHxuWA/mdvIracQ=; b=5R1LoHdy2J6n+Sx4wf+Fuk9Ee0FClXnxYbQdPCrLJbjux1MrOHsiu02SCyG3QNZbyo BvA5gv3GZrI8G7gDXdGq/hEy9kJPbgkv8V2KCisSKYTmIXNBvW8wA3w+a3/DKWwmT5Bs LC3RaPLGSuiMugmYSFmlWWcFQ4uSSr1XPZK5OQIrTEcJXm03KqS/wDIee89RftO8hRgh icK73v3sO9rrow/zqYCSrwyhUasjGxdzp1S9jiNLoeN7WcxAYhL8NWPy1teQH3mFhxdZ z10gdaEx2STij+8VtvS3yt+AZ2AFCvaQ7D4BwOd2V1WkDjKj/X2QVMGWid2AWC24iiK/ v9WA== X-Gm-Message-State: AO0yUKU81An3ieEieDBpXsu/BoMrZhaE5ZXbd7ZKWFzvCPeLK2Tyzl+y z+t0S6GkOqu8UxFbrlSCUJpBcQ== X-Google-Smtp-Source: AK7set/6BEEXgmYfSuBx26vYRX30XJoFC5h6wSJls9a4TP7CtMtQu2cBpLvwjuvajkEE0Haj4Xo/Rw== X-Received: by 2002:a05:622a:4c8:b0:3bf:e05a:f2f2 with SMTP id q8-20020a05622a04c800b003bfe05af2f2mr3622293qtx.31.1678219513431; Tue, 07 Mar 2023 12:05:13 -0800 (PST) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id b3-20020ac85bc3000000b003bfb820f17csm10451542qtb.63.2023.03.07.12.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 12:05:13 -0800 (PST) From: Grant Grundler To: Oleksij Rempel , Pavel Skripkin , Lukas Wunner Cc: Eizan Miyamoto , Jakub Kicinski , netdev , "David S . Miller" , LKML , Grant Grundler Subject: [PATCHv2 2/2] net: asix: init mdiobus from one function Date: Tue, 7 Mar 2023 12:05:02 -0800 Message-Id: <20230307200502.2263655-2-grundler@chromium.org> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog In-Reply-To: <20230307200502.2263655-1-grundler@chromium.org> References: <20230307200502.2263655-1-grundler@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Make asix driver consistent with other drivers (e.g. tg3 and r8169) which use mdiobus calls: setup and tear down be handled in one function each. Signed-off-by: Grant Grundler --- drivers/net/usb/asix_devices.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c index 21845b88a64b9..d7caab4493d15 100644 --- a/drivers/net/usb/asix_devices.c +++ b/drivers/net/usb/asix_devices.c @@ -637,7 +637,7 @@ static int asix_resume(struct usb_interface *intf) return usbnet_resume(intf); } -static int ax88772_init_mdio(struct usbnet *dev) +static int ax88772_mdio_register(struct usbnet *dev) { struct asix_common_private *priv = dev->driver_priv; int ret; @@ -657,10 +657,22 @@ static int ax88772_init_mdio(struct usbnet *dev) ret = mdiobus_register(priv->mdio); if (ret) { netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret); - mdiobus_free(priv->mdio); - priv->mdio = NULL; + goto mdio_register_err; } + priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr); + if (!priv->phydev) { + netdev_err(dev->net, "Could not find PHY\n"); + ret=-ENODEV; + goto mdio_phy_err; + } + + return 0; + +mdio_phy_err: + mdiobus_unregister(priv->mdio); +mdio_register_err: + mdiobus_free(priv->mdio); return ret; } @@ -675,13 +687,6 @@ static int ax88772_init_phy(struct usbnet *dev) struct asix_common_private *priv = dev->driver_priv; int ret; - priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr); - if (!priv->phydev) { - netdev_err(dev->net, "Could not find PHY\n"); - ax88772_mdio_unregister(priv); - return -ENODEV; - } - ret = phy_connect_direct(dev->net, priv->phydev, &asix_adjust_link, PHY_INTERFACE_MODE_INTERNAL); if (ret) { @@ -799,7 +804,7 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) priv->presvd_phy_bmcr = 0; priv->presvd_phy_advertise = 0; - ret = ax88772_init_mdio(dev); + ret = ax88772_mdio_register(dev); if (ret) return ret;