From patchwork Fri Apr 12 10:46:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13627626 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61742C4345F for ; Fri, 12 Apr 2024 10:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=3LPfVtCUX6+NMmYOou1aieVWJn48nP5TiyyTmeCS+Xs=; b=N4Z/WNbA58QHke JR+DCG2KGv2qlfqHPpOPLaoL5dvZhAoyGR254r1LM+ooQBrgwLQvybAWLp8zlhkPsGEhNpQv2OhRs JbqDWCzKvItqDDrP5REcCAhfefIgJgrz/5ELvcfEU/VlHj7x8UiP0OIclkaspRvXLomgPOky0t5/u saomLQilJ6Dy0MwEqKM2P3bZnc7BRhpq4sXbPI0iRRo/9GJNZM4oYxdEEied+V/VC4DPx/mxCTlG5 K5LDrwHNw7N91FCNb8vMQhgDWMvxELI6IeUJhTuyA0sdCOSUgzschTgmMqkTx9cezh3PFwW8EMC16 nQBMbzWUSvazf1RK5fIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvEQP-0000000GmSj-40qf; Fri, 12 Apr 2024 10:46:29 +0000 Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvEQM-0000000GmRC-0QL1 for linux-arm-kernel@lists.infradead.org; Fri, 12 Apr 2024 10:46:28 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 855802000B; Fri, 12 Apr 2024 10:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1712918779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YNgRIU2UT5K1UZWit6Bh8EiB5voBR6xsuvaO369sMeo=; b=DbjrBSH8H+gABaWjk9e+ChddzEQq2eNtOK+JGnuOpIS/mozJBZLVctgS9BA/LBnkCL+OZR pI5qZRzOWugtFgNLXMkMUGVk0Qg1JP9fbt3z7s2fwTCL1qjTbbLy2OiePMZ2Nl3Q8m2hYi aZ9WAoT2DmEw1S/4OaRrcPuTm7fypSsA81FrQebKftryQdjOd1OLeboWXsTGA4Cpw5IBE+ QEIninHkS3+Aa4fE65wVZrX76Pg68NeuhNoeL2726ljbk4vr17Do17x+C27icNZgWb/zQj r/eCdmkuRb5bfQz6+wsKkcCJdoWF6tIYk4of3BDJ4o/RbtFxHRAOKgYRctek1A== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?K=C3=B6ry_Maincent?= , Jesse Brandeburg , =?utf-8?q?Marek_Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?utf-8?q?Nicol=C3=B2_Veronese?= , Simon Horman , mwojtas@chromium.org, Nathan Chancellor Subject: [PATCH net-next] net: phy: phy_link_topology: Handle NULL topologies Date: Fri, 12 Apr 2024 12:46:14 +0200 Message-ID: <20240412104615.3779632-1-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240412_034626_796611_4A12B7ED X-CRM114-Status: GOOD ( 13.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In situations where phylib is a module, the topology can be NULL as it's not initialized at netdev creation. Allow passing a NULL topology pointer to phy_link_topo helpers. Signed-off-by: Maxime Chevallier Closes: https://lore.kernel.org/netdev/2e11b89d-100f-49e7-9c9a-834cc0b82f97@gmail.com/ Closes: https://lore.kernel.org/netdev/20240409201553.GA4124869@dev-arch.thelio-3990X/ --- Hi, This patch fixes a commit that is in net-next, hence the net-next tag and the lack of "Fixes" tag. Nathan, Heiner, can you confirm this solves what you're seeing ? I think we can improve on this solution by moving the topology init at the first PHY insertion and clearing it at netdev destruction. Maxime drivers/net/phy/phy_link_topology.c | 10 +++++++++- include/linux/phy_link_topology.h | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c index 985941c5c558..0f3973f07fac 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -42,6 +42,9 @@ int phy_link_topo_add_phy(struct phy_link_topology *topo, struct phy_device_node *pdn; int ret; + if (!topo) + return 0; + pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); if (!pdn) return -ENOMEM; @@ -93,7 +96,12 @@ EXPORT_SYMBOL_GPL(phy_link_topo_add_phy); void phy_link_topo_del_phy(struct phy_link_topology *topo, struct phy_device *phy) { - struct phy_device_node *pdn = xa_erase(&topo->phys, phy->phyindex); + struct phy_device_node *pdn; + + if (!topo) + return; + + pdn = xa_erase(&topo->phys, phy->phyindex); /* We delete the PHY from the topology, however we don't re-set the * phy->phyindex field. If the PHY isn't gone, we can re-assign it the diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h index 6b79feb607e7..21ca78127d0f 100644 --- a/include/linux/phy_link_topology.h +++ b/include/linux/phy_link_topology.h @@ -40,7 +40,12 @@ struct phy_link_topology { static inline struct phy_device * phy_link_topo_get_phy(struct phy_link_topology *topo, u32 phyindex) { - struct phy_device_node *pdn = xa_load(&topo->phys, phyindex); + struct phy_device_node *pdn; + + if (!topo) + return NULL; + + pdn = xa_load(&topo->phys, phyindex); if (pdn) return pdn->phy;