Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7076999rdb; Wed, 3 Jan 2024 04:02:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHMv3qTPbxxntoICZ/bDINWQqLy1lZ1q7Kqdh8u3JdeBUBJRjRfPiglap5h9k09pskJkzC X-Received: by 2002:a05:6358:514d:b0:170:17eb:9c45 with SMTP id 13-20020a056358514d00b0017017eb9c45mr19147419rwj.38.1704283373136; Wed, 03 Jan 2024 04:02:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704283373; cv=none; d=google.com; s=arc-20160816; b=A9Sl95e7ExrwDqtPy1L6DhaUYGmmByAqIiaOR1b3WfYdmo+TaBjOnaT3iMvPKTfirQ 3yPrcUXhaNjrJ28IVnXKAs12t1VKrvX8LUaesHCUOlpK1hXM5qXdwVWL9ClN2F0dDRiT qh4GXSq0Vw4aHhCZetNDcIJqX7Tx2SUoPNNkW/1MGRICGccMgESPFYJsilDhhWaUpCXW 8o9gFiMobtWc2qH4xZRA5MPdSSR9a2mC96YhAL8N0qvN7KS9LwxC03oGm/OnHB8PiYKI S/oLdHiGh9dQQ2oC/YbWU1N+lu/21eEhcWlPYzPOEQAAX+o6vJAJT2JJjS7raIpYbo15 3cog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=nsC4Et3I1Gf7WygCzSIdwNufdONd9F78NTeV2QKxMqc=; fh=Swf/6A29vGXz903X6Rirt4HE4eGSWgceboEBANk6dD4=; b=rcL50zMoNzvc/hYmIDXze6NIpp0rzuAxOIXPGrohe0FLVMjSCvS1/3CyptNtJ0UdBZ nWh8perU2S7EoSwbAzsqVXgNZLIiJ2hMb+pPaus7hhsABDR0AAWadfPVJhTipSjGoRNm H+Z0WUpi/bM8uB6yxxsAagAyNBblVNc30OwQDwtMXcdhIwX80xoZBaUkg/4+GpE85x2p a/MiXazFlpfabVYRaRKDhCicnDHc0Qe/xJjOFiYOLsAcdFeDsNixcYSRh704Hj3dDD9W 8+uoshCYLCKCvGxgbRQF7B4Tq4Ku8YM5WspQ2je+GtJcdaQ0Qu/cxGxGHpSPOoEcKoh3 rEew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="tONx/tDO"; spf=pass (google.com: domain of linux-kernel+bounces-15485-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15485-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id fd10-20020a056a002e8a00b006daaf315a4fsi1897481pfb.265.2024.01.03.04.02.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:02:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15485-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="tONx/tDO"; spf=pass (google.com: domain of linux-kernel+bounces-15485-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15485-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 683282858F8 for ; Wed, 3 Jan 2024 12:02:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E51919BBB; Wed, 3 Jan 2024 12:01:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="tONx/tDO" X-Original-To: linux-kernel@vger.kernel.org Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6778619BB1; Wed, 3 Jan 2024 12:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=nsC4Et3I1Gf7WygCzSIdwNufdONd9F78NTeV2QKxMqc=; b=tONx/tDO28T27Y2nH3BzU1n1Tx E4R6ocwk6+xW/RH5Cgva06EnXOZSaWJhSBLMLF49cwDbFEBziVCWivL+Dp02qjbKf6dNjz7oq+ey0 mdlY4kfdqfMIamvo+xGaEUykr3N3HIW2lw+lTzqe0hN2FB4Hp6zM9dpyVSNpMX3dGkFRxArWXBiSz fksr6GZOmDJ56+L9OdGnlMfaC/666rZoFCvMh329MzZBY54SDfLqG3cwyWsO9uJHuUPv2a+IW6/z1 10V3Ltl5XgFTYQ5IliDuztXbTDBuCVDWOWucEx7poBakDTe7vsgA5JI7VlhxQqIKBZBFThIN68CFN FKX1IwXw==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:49630) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rKzvr-0007Pn-03; Wed, 03 Jan 2024 12:01:11 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rKzvs-0006LG-KZ; Wed, 03 Jan 2024 12:01:12 +0000 Date: Wed, 3 Jan 2024 12:01:12 +0000 From: "Russell King (Oracle)" To: Luiz Angelo Daros de Luca , kuba@kernel.org Cc: netdev@vger.kernel.org, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] net: mdio: get/put device node during (un)registration Message-ID: References: <20231220045228.27079-2-luizluca@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) On Wed, Jan 03, 2024 at 10:22:00AM +0000, Russell King (Oracle) wrote: > I agree with that approach, but as you rightly point out, we need MDIO > to behave correctly, and I don't think that patching just one bit of > MDIO to fix this mess is the right approach. This is probably a safer approach to ensuring that the firmware data reference count isn't dropped while the bus exists byensuring that we always take a reference at register time. It also likely fixes similar issues with ACPI and swnode based users as well. It doesn't deal with the excess-refcount problem, as with this approach the two issues are entirely independent of each other. Please test to check that this addresses your issue. Thanks. diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 6cf73c15635b..afbad1ad8683 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -193,6 +193,10 @@ static void mdiobus_release(struct device *d) bus->state != MDIOBUS_ALLOCATED, "%s: not in RELEASED or ALLOCATED state\n", bus->id); + + if (bus->state == MDIOBUS_RELEASED) + fwnode_handle_put(dev_fwnode(d)); + kfree(bus); } @@ -684,6 +688,15 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) bus->dev.groups = NULL; dev_set_name(&bus->dev, "%s", bus->id); + /* If the bus state is allocated, we're registering a fresh bus + * that may have a fwnode associated with it. Grab a reference + * to the fwnode. This will be dropped when the bus is released. + * If the bus was set to unregistered, it means that the bus was + * previously registered, and we've already grabbed a reference. + */ + if (bus->state == MDIOBUS_ALLOCATED) + fwnode_handle_get(dev_fwnode(&bus->dev)); + /* We need to set state to MDIOBUS_UNREGISTERED to correctly release * the device in mdiobus_free() * -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!