From: Heiner Kallweit <hkallweit1@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>, Andrew Lunn <andrew+netdev@lunn.ch>,
Russell King - ARM Linux <linux@armlinux.org.uk>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@google.com>,
David Miller <davem@davemloft.net>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: [PATCH net-next 3/4] net: phy: fixed_phy: add helper fixed_phy_find
Date: Sun, 7 Sep 2025 00:01:52 +0200 [thread overview]
Message-ID: <34434ab0-69ba-4a93-bc7a-944e2cf49852@gmail.com> (raw)
In-Reply-To: <e81be066-cc23-4055-aed7-2fbc86da1ff7@gmail.com>
Factor out the functionality to search for a fixed_phy matching an
address. This improves readability of the code.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/fixed_phy.c | 81 +++++++++++++++++++------------------
1 file changed, 42 insertions(+), 39 deletions(-)
diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
index 35ac29c3e..eae513b70 100644
--- a/drivers/net/phy/fixed_phy.c
+++ b/drivers/net/phy/fixed_phy.c
@@ -40,42 +40,49 @@ static struct fixed_mdio_bus platform_fmb = {
.phys = LIST_HEAD_INIT(platform_fmb.phys),
};
-int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)
+static struct fixed_phy *fixed_phy_find(int addr)
{
struct fixed_mdio_bus *fmb = &platform_fmb;
+ struct fixed_phy *fp;
+
+ list_for_each_entry(fp, &fmb->phys, node) {
+ if (fp->addr == addr)
+ return fp;
+ }
+
+ return NULL;
+}
+
+int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)
+{
struct phy_device *phydev = dev->phydev;
struct fixed_phy *fp;
if (!phydev || !phydev->mdio.bus)
return -EINVAL;
- list_for_each_entry(fp, &fmb->phys, node) {
- if (fp->addr == phydev->mdio.addr) {
- fp->status.link = new_carrier;
- return 0;
- }
- }
- return -EINVAL;
+ fp = fixed_phy_find(phydev->mdio.addr);
+ if (!fp)
+ return -EINVAL;
+
+ fp->status.link = new_carrier;
+
+ return 0;
}
EXPORT_SYMBOL_GPL(fixed_phy_change_carrier);
static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
{
- struct fixed_mdio_bus *fmb = bus->priv;
struct fixed_phy *fp;
- list_for_each_entry(fp, &fmb->phys, node) {
- if (fp->addr == phy_addr) {
- /* Issue callback if user registered it. */
- if (fp->link_update)
- fp->link_update(fp->phydev->attached_dev,
- &fp->status);
-
- return swphy_read_reg(reg_num, &fp->status);
- }
- }
+ fp = fixed_phy_find(phy_addr);
+ if (!fp)
+ return 0xffff;
- return 0xFFFF;
+ if (fp->link_update)
+ fp->link_update(fp->phydev->attached_dev, &fp->status);
+
+ return swphy_read_reg(reg_num, &fp->status);
}
static int fixed_mdio_write(struct mii_bus *bus, int phy_addr, int reg_num,
@@ -93,21 +100,19 @@ int fixed_phy_set_link_update(struct phy_device *phydev,
int (*link_update)(struct net_device *,
struct fixed_phy_status *))
{
- struct fixed_mdio_bus *fmb = &platform_fmb;
struct fixed_phy *fp;
if (!phydev || !phydev->mdio.bus)
return -EINVAL;
- list_for_each_entry(fp, &fmb->phys, node) {
- if (fp->addr == phydev->mdio.addr) {
- fp->link_update = link_update;
- fp->phydev = phydev;
- return 0;
- }
- }
+ fp = fixed_phy_find(phydev->mdio.addr);
+ if (!fp)
+ return -ENOENT;
+
+ fp->link_update = link_update;
+ fp->phydev = phydev;
- return -ENOENT;
+ return 0;
}
EXPORT_SYMBOL_GPL(fixed_phy_set_link_update);
@@ -144,17 +149,15 @@ static DEFINE_IDA(phy_fixed_ida);
static void fixed_phy_del(int phy_addr)
{
- struct fixed_mdio_bus *fmb = &platform_fmb;
- struct fixed_phy *fp, *tmp;
+ struct fixed_phy *fp;
- list_for_each_entry_safe(fp, tmp, &fmb->phys, node) {
- if (fp->addr == phy_addr) {
- list_del(&fp->node);
- kfree(fp);
- ida_free(&phy_fixed_ida, phy_addr);
- return;
- }
- }
+ fp = fixed_phy_find(phy_addr);
+ if (!fp)
+ return;
+
+ list_del(&fp->node);
+ kfree(fp);
+ ida_free(&phy_fixed_ida, phy_addr);
}
struct phy_device *fixed_phy_register(const struct fixed_phy_status *status,
--
2.51.0
next prev parent reply other threads:[~2025-09-06 22:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-06 21:59 [PATCH net-next 0/4] net: phy: fixed_phy: improvements Heiner Kallweit
2025-09-06 22:00 ` [PATCH net-next 1/4] net: phy: fixed_phy: remove unused interrupt support Heiner Kallweit
2025-09-06 22:01 ` [PATCH net-next 2/4] net: phy: fixed_phy: remove member no_carrier from struct fixed_phy Heiner Kallweit
2025-09-06 22:01 ` Heiner Kallweit [this message]
2025-09-06 22:02 ` [PATCH net-next 4/4] net: phy: fixed_phy: remove struct fixed_mdio_bus Heiner Kallweit
2025-09-10 1:30 ` [PATCH net-next 0/4] net: phy: fixed_phy: improvements 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=34434ab0-69ba-4a93-bc7a-944e2cf49852@gmail.com \
--to=hkallweit1@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.