From patchwork Tue Mar 14 05:54:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 69315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1591178wrd; Mon, 13 Mar 2023 23:17:36 -0700 (PDT) X-Google-Smtp-Source: AK7set8/WFNEIKH1S4/frvyaDvVvd4tABFDT0aUi2QIsCBZH0a8IYqMzwjnm0gXK1RUwB5ulcaQA X-Received: by 2002:a05:6a20:7925:b0:d5:4ae5:b01c with SMTP id b37-20020a056a20792500b000d54ae5b01cmr1518772pzg.8.1678774656213; Mon, 13 Mar 2023 23:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678774656; cv=none; d=google.com; s=arc-20160816; b=mSldsHtoQiJzeaDZrgyLNaRWd5PjQ879fMuqk29TZ8q4NnLWQ8IxpP8M77DttXlq16 kJX3SZL0BI/StKWMh4a7gCNpDCIffLg5qThDC8PZQ5p3UMnRHssIw8HuR2twKk0iWDVD VbkXCWtT05o40VYa0IpNPIw8hdgPMM7fWzehxN4/T+fOVfR6V2sZznx7YkPpgIBqWszM xRghHSzwElLt7dgy/LbS/4eOuYdjxnCAIwGpB1r8fgMXBE4VvP5A/6rWHDDA7yXYSnw9 4ZjC7mNYYRWa7DPxVWY8MgnbLCHWq/zVsLxHSBiz8oGhOcrtsoPxADz1NGYZIlhAk32k cD/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=cZUrcOEwApRsFF25slrbmDsKbhdNNu2L1mi9TI+ryy4=; b=jqnnPvE9OAS8SRRbX9sLrjNBTcRh/okatU8hdFlzs22UBYQlwpUierkJq7FB8+nZyQ ymmamEwjyPjgPfjWMGuCFRhOZUbSqoBG8HilRXMu+gmbgYtvjahT8AGczCvXM9IPTxIx 2d99rZ7jbVonvnrya3dt8bQBOiBgHAFTjfsEJEhF4saPjzXIxSJAshGYBpfs7ZWpBu3i 74QFkVJ/y85boEoX/rQNZ0q2o3JzrxocR2tIJnXJdOIwNIFcsmoA1lIY3eHihkfw6Fkj HFIy50Ld3BZsr19uP1WV1yqyuMgA+xErHHWPjbyz8pUCQZMd7nlL7tbzhN1xtSCaGapo 0a4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=F37hpRYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u19-20020a634713000000b0050303dea3f0si1561281pga.572.2023.03.13.23.17.21; Mon, 13 Mar 2023 23:17:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=F37hpRYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbjCNFy3 (ORCPT + 99 others); Tue, 14 Mar 2023 01:54:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbjCNFy0 (ORCPT ); Tue, 14 Mar 2023 01:54:26 -0400 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 DB4038C957 for ; Mon, 13 Mar 2023 22:54:22 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id s12so15635154qtq.11 for ; Mon, 13 Mar 2023 22:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678773262; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=cZUrcOEwApRsFF25slrbmDsKbhdNNu2L1mi9TI+ryy4=; b=F37hpRYBwdfYrlsTtUAUMX2Zy2J+8I1jy2liucRyNHGHvGvpXQujLUWrPdvwOixeKj n8//XY94bBsm1R052ih5K9lLmB9ypIXKS+CUJVvrbPXgBX+wL/LuhJMFcMKRE+yzZrXG B95elN27gPHUf6+7Clk0PUfaeWkUOY9USrO0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678773262; 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=cZUrcOEwApRsFF25slrbmDsKbhdNNu2L1mi9TI+ryy4=; b=lAQrJaJ45wOeKkxKhuFZKQO+i5j0/Rk0zxnLkbe7mdgXoQ/b5VoczXZWlWyFh9ETYf AJWdFJwaeL+064ATeeiW06bJUff+YfTqJMzzRhte2rPaf0FgQpFUUxzA/PxFKaX+40dx +o5PYUGB4EHBeQPYR2b1f0yUV1O0FBzxWnTOACvs/IRsTVSVuPX3YFMQN3BmbDmsb0FX qskOpvTJFS8sbQmVWFsHfbtzi136H2MwDaBk14tU8YaK65hrd5hBV9iBE5xdLUoxfyVR qnYD+KgK3/7XxE+RkrLxq9rLcNjZCFZU0Jv0aFcAniZ10S4EOImlX5yjyjBjXrx0kPzb 4p3A== X-Gm-Message-State: AO0yUKWhUmpmgFZmUdIso1boAAB3iuJx/Ggeiv/tZ3Y4BaLdx0ay7ZfK P9WfwCPfP7ZuT1P/ar/VXwhHIQ== X-Received: by 2002:a05:622a:46:b0:3b8:6a20:675e with SMTP id y6-20020a05622a004600b003b86a20675emr33906851qtw.29.1678773261970; Mon, 13 Mar 2023 22:54:21 -0700 (PDT) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id z9-20020ac86b89000000b003b9bb59543fsm1195290qts.61.2023.03.13.22.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 22:54:21 -0700 (PDT) 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: [PATCHv4 net] net: asix: fix modprobe "sysfs: cannot create duplicate filename" Date: Mon, 13 Mar 2023 22:54:10 -0700 Message-Id: <20230314055410.3329480-1-grundler@chromium.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760322813898755299?= X-GMAIL-MSGID: =?utf-8?q?1760322813898755299?= "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 (link below). 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 Link: https://lore.kernel.org/netdev/20220623063649.GD23685@pengutronix.de/T/ Tested-by: Eizan Miyamoto Signed-off-by: Grant Grundler Reviewed-by: Michal Swiatkowski --- drivers/net/usb/asix_devices.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) V4: add mdio_unregister to ax88172_bind() error handling paths V3: rebase against netdev/net.git remove "TEST" prefix in subject line added Link: tag for Reported-by tag 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 743cbf5d662c..b758010bab36 100644 --- a/drivers/net/usb/asix_devices.c +++ b/drivers/net/usb/asix_devices.c @@ -666,8 +666,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; @@ -679,7 +680,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) @@ -690,6 +704,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; } @@ -896,16 +911,23 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) ret = ax88772_init_mdio(dev); if (ret) - return ret; + goto mdio_err; ret = ax88772_phylink_setup(dev); if (ret) - return ret; + goto phylink_err; ret = ax88772_init_phy(dev); if (ret) - phylink_destroy(priv->phylink); + goto initphy_err; + return 0; + +initphy_err: + phylink_destroy(priv->phylink); +phylink_err: + ax88772_mdio_unregister(priv); +mdio_err: return ret; } @@ -926,6 +948,7 @@ static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf) phylink_disconnect_phy(priv->phylink); rtnl_unlock(); phylink_destroy(priv->phylink); + ax88772_mdio_unregister(priv); asix_rx_fixup_common_free(dev->driver_priv); }