Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp57338lql; Fri, 12 Apr 2024 03:46:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbfeo+NMQAsDpKdBb0DrfHFe87qOiZzM8UeLzdXD3u0GX78YOaZh/0AmsUf6V9ot32DBa+7G087/LL3BGxUDhtrkuaPVXbHwBjkO3HdA== X-Google-Smtp-Source: AGHT+IGj/14S9mZCPsOAmsKgMRfbZ6+v+8OOBb7PmEPTMpUZT4J23fv2G6GER/aelNvWkjYCo/LG X-Received: by 2002:a17:90b:97:b0:2a2:a19f:98b4 with SMTP id bb23-20020a17090b009700b002a2a19f98b4mr2033388pjb.20.1712918793153; Fri, 12 Apr 2024 03:46:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712918793; cv=pass; d=google.com; s=arc-20160816; b=fcQR7gPyYpZxLBmets1VTbavWWLx0xM9WtSHXr7YsGfdjGkoq0wreYjQWO8Objxzka aGYTCxRBfbfBNmZWzXre766PoCQovurUWYbNPZNoAKDTMY0D2p2lblaLXYav4t+zwNXO z1xkZz56njCRyeFyfJFMUCKw8pLYl4+xA9Ti1fgCMUvR8exeyaPe++iltbM+bcLng6Ap Wbfs3y/JpZeuZNgQGmNfJEjN5CbqKteDVPDuyYxxlljZZ+GsN46fPR0vHRfJIej0zJp2 u3G84PSYvtdmlyd1PLM6swADBPHXcZSwPyE1sOzAUcHyUVMftCmIB5Xj1xOXVxLzVEwN CINQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=YNgRIU2UT5K1UZWit6Bh8EiB5voBR6xsuvaO369sMeo=; fh=Lo1oyO0mz0P2SxrC2jFPEOxcMBGBNgLp52EfFCk4+8s=; b=Tzu2NkzB7xRBEBmaT1SDSKijAf9HoI31v0UmSA2T5+fGSeMCuB3aLXN1Oz4VnE12T9 j+816RxCi50/yp+/TEn0BYSg/YmIzbCFW1qnXrfBM6+F8jj4mEDrr/oD2YY+n9SfUGs6 kU6AhzEUDmrFj3oHaPqidk1mt9bugixwUbE7HE68VWKVt+UvAFjTXKhcQKlJSpq+aEwW wFLvBLjGxp4YWhjgR6hQ7S/SH2XP288LEhw9F75J33bmSz57h429QxQ90Aj0Js/qTkVr 030BdIN7tz5tfhbtnx9j2rDkpK1uHwzZg5J84J4cWCKDSTaVrx1rta6hvM3XghlUtghR Sv/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=DbjrBSH8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-142527-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142527-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id co24-20020a17090afe9800b002a01f8b865bsi5231788pjb.80.2024.04.12.03.46.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 03:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142527-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=pass header.i=@bootlin.com header.s=gm1 header.b=DbjrBSH8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-142527-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142527-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com 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 B9D0A28B572 for ; Fri, 12 Apr 2024 10:46:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED40543AD7; Fri, 12 Apr 2024 10:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="DbjrBSH8" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 5323620310; Fri, 12 Apr 2024 10:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712918784; cv=none; b=Jh8rNeHPUfbNwfyNePksHWbA1yom/YErxWaibCvH2SXgPjt6IWrwnY4o5xbOMi1rXh/fmiKSNWs4zFa/HRTpwSUmxiVO8X31ZZCzaCelDxgPs+oOF2xkkD9xCuHOhAaTxT79YTdr2N7jp+SNMOc0TkrATZ95sCqOpQQMUAXaNX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712918784; c=relaxed/simple; bh=Cu3HN4Jc80J7VKYfW/r+tTVJEg6eOmO7O5fflj7dDWw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oNEp3Y2i72cotwxeZfOxwgkdiC49zaNlLqhVDfxXTENtNUpoarb+X56fM2fLEotdDyeCGxpUnetWG3QyxXmdwA74rTEFlVMYVuHG8ApqmT2TRMnR2TLVihIhRYHu60+y5wDxsbPcO1UbKIFEjyPn/DPD2A3j/2QOZATPBnOIfsM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=DbjrBSH8; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com 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=20Maincent?= , Jesse Brandeburg , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: maxime.chevallier@bootlin.com 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; -- 2.44.0