Message ID | 20231117162323.626979-5-maxime.chevallier@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp618196vqn; Fri, 17 Nov 2023 07:40:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcQxt5HgbtGkk6VphonT20kkuuJlVU180WOtAzb8iJB3adf5iacdQsCPW6cmUuBOuMotZi X-Received: by 2002:a05:6808:aa2:b0:3ae:170f:a39b with SMTP id r2-20020a0568080aa200b003ae170fa39bmr21154963oij.17.1700235648044; Fri, 17 Nov 2023 07:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700235648; cv=none; d=google.com; s=arc-20160816; b=Fs7/lIg6Nknyz/t0Yh+sZ1vrj/ZkI7d6+2KPuZU4k/FLJM4UQ5dcQPGBatq6OZxSL2 wkoMbxPMOS7f+c7gu+toOijJiu1yEMBPJa3mGx/htKb0f3qlp/5FxRvzsJXDOpqWyUR8 sXHVHuR9QFdmKrrzYnSAdbq2V9IWZZ100CtjXKZEW39sKR6sQwO2kd6PvsjlHOS5z/Jg hMGUnKjMzDCbQWFtR4jXOvvW0KShVmfL1U3HpZ2uMo9vUk43Un1AkKR1RlQ+LhW3+hq2 ilOJ015nhvsBn/qCeQRwlex9rjD62AFkx9imz2aytlMUj5Lm9hDFC+obiQOmDcMSAcfa S/ZA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rRo/pQcZejgRnemKP4uNQxIXQrj56PAQ2aabjMSpgaA=; fh=1WRQxG55ASsvt/9NxVDhUbJ1aQecLyVglFoTAx66NyA=; b=RFCx1k5o5W+cbp7bAexPVKefad1SN/MexW9eloweQ2UAtPt31vjXEHTPRv0Y0/N1vm Sfzn88T7+WUce5rrPxOE7FFqQr760Aooi7zuGETvvmjyb068KLLd73puyTfzcCRQdAfn r5xX6OPH3eksc7oU5v+JeTSg7Apt69FeWVH4P7/MhIiF0dU+khRc6+DhSHx3dw5JtLSc edQsakxay2qkxMOYKMUDLqDYFD+K94H/CSmALKlqUDia5F8DHJVNCBNLCvrUbsSUVm6Y OPfyGmUAbbex0EqYf1iThD9+gix43kRVSvITxosO6JB8tH5v6UFO/D352SeE2Ovf1QCF jX3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GnhtVcTe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bx15-20020a056a02050f00b005b91536981csi2410159pgb.11.2023.11.17.07.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 07:40:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GnhtVcTe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D0255827FF8E; Fri, 17 Nov 2023 07:40:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346069AbjKQPkf (ORCPT <rfc822;jaysivo@gmail.com> + 30 others); Fri, 17 Nov 2023 10:40:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232348AbjKQPk0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Nov 2023 10:40:26 -0500 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92F0910D0; Fri, 17 Nov 2023 07:40:22 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 703451BF211; Fri, 17 Nov 2023 15:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1700235621; 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: in-reply-to:in-reply-to:references:references; bh=rRo/pQcZejgRnemKP4uNQxIXQrj56PAQ2aabjMSpgaA=; b=GnhtVcTeeFqGMaAcovX1o3xPo/YAWPfzDS9rVjV7Qcv7xceupy2l5m9E9wXuXb7XB5Nbqz 9zCF+d6vMutig1CM32SZHX3qyFliuI6TSuSU+pVWZVgWEDI2/xoi/oGMO2ns7Di2vVjdUp y6t7kSCWp9Q1M4UefMNzQedp5vrtRrNdRCkEo5wxqU1U6X+Sy7e85y9hux490ttCcCXLpG 6NC5rfPOPYZl4fRe3x/wQQlvnYJsRyS3kEb01suvfauDbSsc++V14l7qEBBDf5KOphcIc3 UnwYdnCOszVKHAyRhxu0SZuYFlAdxgAlo5T1buzTI9GnQyxqzj3tQZQo/5vj2g== From: Maxime Chevallier <maxime.chevallier@bootlin.com> To: davem@davemloft.net Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn <andrew@lunn.ch>, Jakub Kicinski <kuba@kernel.org>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, Russell King <linux@armlinux.org.uk>, linux-arm-kernel@lists.infradead.org, Christophe Leroy <christophe.leroy@csgroup.eu>, Herve Codina <herve.codina@bootlin.com>, Florian Fainelli <f.fainelli@gmail.com>, Heiner Kallweit <hkallweit1@gmail.com>, Vladimir Oltean <vladimir.oltean@nxp.com>, =?utf-8?q?K=C3=B6ry_Maincent?= <kory.maincent@bootlin.com>, Jesse Brandeburg <jesse.brandeburg@intel.com> Subject: [RFC PATCH net-next v2 04/10] net: sfp: Add helper to return the SFP bus name Date: Fri, 17 Nov 2023 17:23:15 +0100 Message-ID: <20231117162323.626979-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231117162323.626979-1-maxime.chevallier@bootlin.com> References: <20231117162323.626979-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: maxime.chevallier@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 07:40:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782826295085342691 X-GMAIL-MSGID: 1782826295085342691 |
Series |
Introduce PHY listing and link_topology tracking
|
|
Commit Message
Maxime Chevallier
Nov. 17, 2023, 4:23 p.m. UTC
Knowing the bus name is helpful when we want to expose the link topology
to userspace, add a helper to return the SFP bus name.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/phy/sfp-bus.c | 9 +++++++++
include/linux/sfp.h | 6 ++++++
2 files changed, 15 insertions(+)
Comments
> +const char *sfp_get_name(struct sfp_bus *bus) > +{ > + if (bus->sfp_dev) > + return dev_name(bus->sfp_dev); > + > + return NULL; > +} Locking? Do you assume rtnl? Does this function need to take rtnl? Andrew
On Tue, Nov 21, 2023 at 02:00:58AM +0100, Andrew Lunn wrote: > > +const char *sfp_get_name(struct sfp_bus *bus) > > +{ > > + if (bus->sfp_dev) > > + return dev_name(bus->sfp_dev); > > + > > + return NULL; > > +} > > Locking? Do you assume rtnl? Does this function need to take rtnl? Yes, rtnl needs to be held to safely access bus->sfp_dev, and that either needs to happen in this function, or be documented as being requried (and ASSERT_RTNL() added here.) The reason is that sfp_dev is the SFP socket device which can be unbound via sfp_unregister_socket(), which will set bus->sfp_dev to NULL. This could race with the above.
Hi Andrew, Russell, On Tue, 21 Nov 2023 10:20:43 +0000 "Russell King (Oracle)" <linux@armlinux.org.uk> wrote: > On Tue, Nov 21, 2023 at 02:00:58AM +0100, Andrew Lunn wrote: > > > +const char *sfp_get_name(struct sfp_bus *bus) > > > +{ > > > + if (bus->sfp_dev) > > > + return dev_name(bus->sfp_dev); > > > + > > > + return NULL; > > > +} > > > > Locking? Do you assume rtnl? Does this function need to take rtnl? > > Yes, rtnl needs to be held to safely access bus->sfp_dev, and that > either needs to happen in this function, or be documented as being > requried (and ASSERT_RTNL() added here.) > > The reason is that sfp_dev is the SFP socket device which can be > unbound via sfp_unregister_socket(), which will set bus->sfp_dev to > NULL. This could race with the above. > That's right, I'll add an assert and document it, thanks for spotting this. Maxime
diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c index f42e9a082935..835fb2271b12 100644 --- a/drivers/net/phy/sfp-bus.c +++ b/drivers/net/phy/sfp-bus.c @@ -859,3 +859,12 @@ void sfp_unregister_socket(struct sfp_bus *bus) sfp_bus_put(bus); } EXPORT_SYMBOL_GPL(sfp_unregister_socket); + +const char *sfp_get_name(struct sfp_bus *bus) +{ + if (bus->sfp_dev) + return dev_name(bus->sfp_dev); + + return NULL; +} +EXPORT_SYMBOL_GPL(sfp_get_name); diff --git a/include/linux/sfp.h b/include/linux/sfp.h index 0573e53b0c11..96f7644908bd 100644 --- a/include/linux/sfp.h +++ b/include/linux/sfp.h @@ -570,6 +570,7 @@ struct sfp_bus *sfp_bus_find_fwnode(const struct fwnode_handle *fwnode); int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream, const struct sfp_upstream_ops *ops); void sfp_bus_del_upstream(struct sfp_bus *bus); +const char *sfp_get_name(struct sfp_bus *bus); #else static inline int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id, @@ -648,6 +649,11 @@ static inline int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream, static inline void sfp_bus_del_upstream(struct sfp_bus *bus) { } + +static const char *sfp_get_name(struct sfp_bus *bus) +{ + return NULL; +} #endif #endif