Message ID | E1q2UT1-008PAg-RS@rmk-PC.armlinux.org.uk (mailing list archive) |
---|---|
State | Accepted |
Commit | 86b5f2d8cd7828c881036d30ce3a4e711a071726 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: pcs: add helpers to xpcs and lynx to manage mdiodev | expand |
Context | Check | Description |
---|---|---|
netdev/series_format | success | Posting correctly formatted |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 8 this patch: 8 |
netdev/cc_maintainers | success | CCed 9 of 9 maintainers |
netdev/build_clang | success | Errors and warnings before: 8 this patch: 8 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/deprecated_api | success | None detected |
netdev/check_selftest | success | No net selftest shell script |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 8 this patch: 8 |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 54 lines checked |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
Fri, May 26, 2023 at 11:14:39AM +0100, Russell King (Oracle) kirjoitti: > Add lynx_pcs_create_mdiodev() to simplify the creation of the mdio > device associated with lynx PCS. In order to allow lynx_pcs_destroy() > to clean this up, we need to arrange for lynx_pcs_create() to take a > refcount on the mdiodev, and lynx_pcs_destroy() to put it. > > Adding the refcounting to lynx_pcs_create()..lynx_pcs_destroy() will > be transparent to existing users of these interfaces. ... > + mdio_device_get(mdio); > lynx->mdio = mdio; Just for the sake of example of how it can be used (taking into account my previous comment): lynx->mdio = mdio_device_get(mdio);
On Fri, May 26, 2023 at 11:14:39AM +0100, Russell King (Oracle) wrote: > Add lynx_pcs_create_mdiodev() to simplify the creation of the mdio > device associated with lynx PCS. In order to allow lynx_pcs_destroy() > to clean this up, we need to arrange for lynx_pcs_create() to take a > refcount on the mdiodev, and lynx_pcs_destroy() to put it. > > Adding the refcounting to lynx_pcs_create()..lynx_pcs_destroy() will > be transparent to existing users of these interfaces. > > Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew
On Fri, May 26, 2023 at 11:14:39AM +0100, Russell King (Oracle) wrote: > Add lynx_pcs_create_mdiodev() to simplify the creation of the mdio > device associated with lynx PCS. In order to allow lynx_pcs_destroy() > to clean this up, we need to arrange for lynx_pcs_create() to take a > refcount on the mdiodev, and lynx_pcs_destroy() to put it. > > Adding the refcounting to lynx_pcs_create()..lynx_pcs_destroy() will > be transparent to existing users of these interfaces. > > Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Reviewed-by: Ioana Ciornei <ioana.ciornei@nxp.com> Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com>
diff --git a/drivers/net/pcs/pcs-lynx.c b/drivers/net/pcs/pcs-lynx.c index 622c3de3f3a8..f04dc580ffb8 100644 --- a/drivers/net/pcs/pcs-lynx.c +++ b/drivers/net/pcs/pcs-lynx.c @@ -323,6 +323,7 @@ struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio) if (!lynx) return NULL; + mdio_device_get(mdio); lynx->mdio = mdio; lynx->pcs.ops = &lynx_pcs_phylink_ops; lynx->pcs.poll = true; @@ -331,10 +332,40 @@ struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio) } EXPORT_SYMBOL(lynx_pcs_create); +struct phylink_pcs *lynx_pcs_create_mdiodev(struct mii_bus *bus, int addr) +{ + struct mdio_device *mdio; + struct phylink_pcs *pcs; + + mdio = mdio_device_create(bus, addr); + if (IS_ERR(mdio)) + return ERR_CAST(mdio); + + pcs = lynx_pcs_create(mdio); + + /* Convert failure to create the PCS to an error pointer, so this + * function has a consistent return value strategy. + */ + if (!pcs) + pcs = ERR_PTR(-ENOMEM); + + /* lynx_create() has taken a refcount on the mdiodev if it was + * successful. If lynx_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 + * lynx_destroy() to automatically free the mdio device. + */ + mdio_device_put(mdio); + + return pcs; +} +EXPORT_SYMBOL(lynx_pcs_create_mdiodev); + void lynx_pcs_destroy(struct phylink_pcs *pcs) { struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs); + mdio_device_put(lynx->mdio); kfree(lynx); } EXPORT_SYMBOL(lynx_pcs_destroy); diff --git a/include/linux/pcs-lynx.h b/include/linux/pcs-lynx.h index 5712cc2ce775..885b59d10581 100644 --- a/include/linux/pcs-lynx.h +++ b/include/linux/pcs-lynx.h @@ -12,6 +12,7 @@ struct mdio_device *lynx_get_mdio_device(struct phylink_pcs *pcs); struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio); +struct phylink_pcs *lynx_pcs_create_mdiodev(struct mii_bus *bus, int addr); void lynx_pcs_destroy(struct phylink_pcs *pcs);
Add lynx_pcs_create_mdiodev() to simplify the creation of the mdio device associated with lynx PCS. In order to allow lynx_pcs_destroy() to clean this up, we need to arrange for lynx_pcs_create() to take a refcount on the mdiodev, and lynx_pcs_destroy() to put it. Adding the refcounting to lynx_pcs_create()..lynx_pcs_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-lynx.c | 31 +++++++++++++++++++++++++++++++ include/linux/pcs-lynx.h | 1 + 2 files changed, 32 insertions(+)