diff options
author | Maxime Chevallier <maxime.chevallier@bootlin.com> | 2024-08-21 17:09:58 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2024-08-23 13:04:34 +0100 |
commit | 0a2f7de0f3b96c4a30e56d2c79f8d812f89599a1 (patch) | |
tree | b832b201de1e60accc9aed5e89535c37ed6e61e7 /drivers/net/phy | |
parent | b2db6f4ace72e71fa09b8d1354f8ac9854140d74 (diff) | |
download | lwn-0a2f7de0f3b96c4a30e56d2c79f8d812f89599a1.tar.gz lwn-0a2f7de0f3b96c4a30e56d2c79f8d812f89599a1.zip |
net: sfp: Add helper to return the SFP bus name
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.
This call will always be made while holding the RTNL which ensures
that the SFP driver won't unbind from the device. The returned pointer
to the bus name will only be used while RTNL is held.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Suggested-by: "Russell King (Oracle)" <linux@armlinux.org.uk>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy')
-rw-r--r-- | drivers/net/phy/sfp-bus.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c index 56953e66bb7b..f13c00b5b449 100644 --- a/drivers/net/phy/sfp-bus.c +++ b/drivers/net/phy/sfp-bus.c @@ -722,6 +722,28 @@ void sfp_bus_del_upstream(struct sfp_bus *bus) } EXPORT_SYMBOL_GPL(sfp_bus_del_upstream); +/** + * sfp_get_name() - Get the SFP device name + * @bus: a pointer to the &struct sfp_bus structure for the sfp module + * + * Gets the SFP device's name, if @bus has a registered socket. Callers must + * hold RTNL, and the returned name is only valid until RTNL is released. + * + * Returns: + * - The name of the SFP device registered with sfp_register_socket() + * - %NULL if no device was registered on @bus + */ +const char *sfp_get_name(struct sfp_bus *bus) +{ + ASSERT_RTNL(); + + if (bus->sfp_dev) + return dev_name(bus->sfp_dev); + + return NULL; +} +EXPORT_SYMBOL_GPL(sfp_get_name); + /* Socket driver entry points */ int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev) { |