Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: fixed_phy: add helper fixed_phy_find

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>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Heiner Kallweit and committed by
Jakub Kicinski
f8db55c8 0625b3bf

+41 -38
+41 -38
drivers/net/phy/fixed_phy.c
··· 40 40 .phys = LIST_HEAD_INIT(platform_fmb.phys), 41 41 }; 42 42 43 - int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier) 43 + static struct fixed_phy *fixed_phy_find(int addr) 44 44 { 45 45 struct fixed_mdio_bus *fmb = &platform_fmb; 46 + struct fixed_phy *fp; 47 + 48 + list_for_each_entry(fp, &fmb->phys, node) { 49 + if (fp->addr == addr) 50 + return fp; 51 + } 52 + 53 + return NULL; 54 + } 55 + 56 + int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier) 57 + { 46 58 struct phy_device *phydev = dev->phydev; 47 59 struct fixed_phy *fp; 48 60 49 61 if (!phydev || !phydev->mdio.bus) 50 62 return -EINVAL; 51 63 52 - list_for_each_entry(fp, &fmb->phys, node) { 53 - if (fp->addr == phydev->mdio.addr) { 54 - fp->status.link = new_carrier; 55 - return 0; 56 - } 57 - } 58 - return -EINVAL; 64 + fp = fixed_phy_find(phydev->mdio.addr); 65 + if (!fp) 66 + return -EINVAL; 67 + 68 + fp->status.link = new_carrier; 69 + 70 + return 0; 59 71 } 60 72 EXPORT_SYMBOL_GPL(fixed_phy_change_carrier); 61 73 62 74 static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num) 63 75 { 64 - struct fixed_mdio_bus *fmb = bus->priv; 65 76 struct fixed_phy *fp; 66 77 67 - list_for_each_entry(fp, &fmb->phys, node) { 68 - if (fp->addr == phy_addr) { 69 - /* Issue callback if user registered it. */ 70 - if (fp->link_update) 71 - fp->link_update(fp->phydev->attached_dev, 72 - &fp->status); 78 + fp = fixed_phy_find(phy_addr); 79 + if (!fp) 80 + return 0xffff; 73 81 74 - return swphy_read_reg(reg_num, &fp->status); 75 - } 76 - } 82 + if (fp->link_update) 83 + fp->link_update(fp->phydev->attached_dev, &fp->status); 77 84 78 - return 0xFFFF; 85 + return swphy_read_reg(reg_num, &fp->status); 79 86 } 80 87 81 88 static int fixed_mdio_write(struct mii_bus *bus, int phy_addr, int reg_num, ··· 100 93 int (*link_update)(struct net_device *, 101 94 struct fixed_phy_status *)) 102 95 { 103 - struct fixed_mdio_bus *fmb = &platform_fmb; 104 96 struct fixed_phy *fp; 105 97 106 98 if (!phydev || !phydev->mdio.bus) 107 99 return -EINVAL; 108 100 109 - list_for_each_entry(fp, &fmb->phys, node) { 110 - if (fp->addr == phydev->mdio.addr) { 111 - fp->link_update = link_update; 112 - fp->phydev = phydev; 113 - return 0; 114 - } 115 - } 101 + fp = fixed_phy_find(phydev->mdio.addr); 102 + if (!fp) 103 + return -ENOENT; 116 104 117 - return -ENOENT; 105 + fp->link_update = link_update; 106 + fp->phydev = phydev; 107 + 108 + return 0; 118 109 } 119 110 EXPORT_SYMBOL_GPL(fixed_phy_set_link_update); 120 111 ··· 149 144 150 145 static void fixed_phy_del(int phy_addr) 151 146 { 152 - struct fixed_mdio_bus *fmb = &platform_fmb; 153 - struct fixed_phy *fp, *tmp; 147 + struct fixed_phy *fp; 154 148 155 - list_for_each_entry_safe(fp, tmp, &fmb->phys, node) { 156 - if (fp->addr == phy_addr) { 157 - list_del(&fp->node); 158 - kfree(fp); 159 - ida_free(&phy_fixed_ida, phy_addr); 160 - return; 161 - } 162 - } 149 + fp = fixed_phy_find(phy_addr); 150 + if (!fp) 151 + return; 152 + 153 + list_del(&fp->node); 154 + kfree(fp); 155 + ida_free(&phy_fixed_ida, phy_addr); 163 156 } 164 157 165 158 struct phy_device *fixed_phy_register(const struct fixed_phy_status *status,