From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>
Cc: Jiawen Wu <jiawenwu@trustnetic.com>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Simon Horman <simon.horman@corigine.com>,
Jose Abreu <Jose.Abreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Subject: [PATCH net-next 2/6] net: pcs: xpcs: add xpcs_create_mdiodev()
Date: Fri, 26 May 2023 11:14:29 +0100 [thread overview]
Message-ID: <E1q2USr-008PAU-Kk@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <ZHCGZ8IgAAwr8bla@shell.armlinux.org.uk>
Add xpcs_create_mdiodev() to simplify the creation of the mdio device
associated with the XPCS. In order to allow xpcs_destroy() to clean
this up, we need to arrange for xpcs_create() to take a refcount on
the mdiodev, and xpcs_destroy() to put it.
Adding the refcounting to xpcs_create()..xpcs_destroy() will be
transparent to existing users of these interfaces.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/pcs/pcs-xpcs.c | 28 ++++++++++++++++++++++++++++
include/linux/pcs/pcs-xpcs.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
index 736776e40c25..1ba214429e01 100644
--- a/drivers/net/pcs/pcs-xpcs.c
+++ b/drivers/net/pcs/pcs-xpcs.c
@@ -1235,6 +1235,7 @@ struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
if (!xpcs)
return ERR_PTR(-ENOMEM);
+ mdio_device_get(mdiodev);
xpcs->mdiodev = mdiodev;
xpcs_id = xpcs_get_id(xpcs);
@@ -1267,6 +1268,7 @@ struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
ret = -ENODEV;
out:
+ mdio_device_put(mdiodev);
kfree(xpcs);
return ERR_PTR(ret);
@@ -1275,8 +1277,34 @@ EXPORT_SYMBOL_GPL(xpcs_create);
void xpcs_destroy(struct dw_xpcs *xpcs)
{
+ if (xpcs)
+ mdio_device_put(xpcs->mdiodev);
kfree(xpcs);
}
EXPORT_SYMBOL_GPL(xpcs_destroy);
+struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr,
+ phy_interface_t interface)
+{
+ struct mdio_device *mdiodev;
+ struct dw_xpcs *xpcs;
+
+ mdiodev = mdio_device_create(bus, addr);
+ if (IS_ERR(mdiodev))
+ return ERR_CAST(mdiodev);
+
+ xpcs = xpcs_create(mdiodev, interface);
+
+ /* xpcs_create() has taken a refcount on the mdiodev if it was
+ * successful. If xpcs_create() fails, this will free the mdio
+ * device here. In any case, we don't need to hold our reference
+ * anymore, and putting it here will allow mdio_device_put() in
+ * xpcs_destroy() to automatically free the mdio device.
+ */
+ mdio_device_put(mdiodev);
+
+ return xpcs;
+}
+EXPORT_SYMBOL_GPL(xpcs_create_mdiodev);
+
MODULE_LICENSE("GPL v2");
diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h
index d2da1e0b4a92..a99972a6d046 100644
--- a/include/linux/pcs/pcs-xpcs.h
+++ b/include/linux/pcs/pcs-xpcs.h
@@ -37,6 +37,8 @@ int xpcs_config_eee(struct dw_xpcs *xpcs, int mult_fact_100ns,
int enable);
struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
phy_interface_t interface);
+struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr,
+ phy_interface_t interface);
void xpcs_destroy(struct dw_xpcs *xpcs);
#endif /* __LINUX_PCS_XPCS_H */
--
2.30.2
next prev parent reply other threads:[~2023-05-26 10:14 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 10:13 [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev Russell King (Oracle)
2023-05-26 10:14 ` [PATCH net-next 1/6] net: mdio: add mdio_device_get() and mdio_device_put() Russell King (Oracle)
2023-05-26 18:20 ` andy.shevchenko
2023-05-29 15:21 ` Andrew Lunn
2023-05-29 20:34 ` Andy Shevchenko
2023-05-29 22:41 ` Russell King (Oracle)
2023-05-29 15:18 ` Andrew Lunn
2023-05-26 10:14 ` Russell King (Oracle) [this message]
2023-05-29 15:25 ` [PATCH net-next 2/6] net: pcs: xpcs: add xpcs_create_mdiodev() Andrew Lunn
2023-05-29 16:05 ` Russell King (Oracle)
2023-05-29 16:27 ` Vladimir Oltean
2023-05-26 10:14 ` [PATCH net-next 3/6] net: stmmac: use xpcs_create_mdiodev() Russell King (Oracle)
2023-05-29 15:26 ` Andrew Lunn
2023-05-26 10:14 ` [PATCH net-next 4/6] net: pcs: lynx: add lynx_pcs_create_mdiodev() Russell King (Oracle)
2023-05-26 18:22 ` andy.shevchenko
2023-05-29 15:28 ` Andrew Lunn
2023-05-29 17:08 ` Ioana Ciornei
2023-05-26 10:14 ` [PATCH net-next 5/6] net: dsa: ocelot: use lynx_pcs_create_mdiodev() Russell King (Oracle)
2023-05-29 15:28 ` Andrew Lunn
2023-05-29 15:47 ` Vladimir Oltean
2023-05-26 10:14 ` [PATCH net-next 6/6] net: enetc: " Russell King (Oracle)
2023-05-29 15:29 ` Andrew Lunn
2023-05-29 15:46 ` Vladimir Oltean
2023-05-30 5:00 ` [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1q2USr-008PAU-Kk@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=Jose.Abreu@synopsys.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=jiawenwu@trustnetic.com \
--cc=kuba@kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=simon.horman@corigine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).