aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/phy
diff options
context:
space:
mode:
authorLennert Buytenhek <buytenh@marvell.com>2008-10-08 19:29:57 -0400
committerDavid S. Miller <davem@davemloft.net>2008-10-08 19:29:57 -0400
commit298cf9beb9679522de995e249eccbd82f7c51999 (patch)
treecabbc9c696a063982aea9a24d8caa667daa33a1a /drivers/net/phy
parent18ee49ddb0d242ed1d0e273038d5e4f6de7379d3 (diff)
phylib: move to dynamic allocation of struct mii_bus
This patch introduces mdiobus_alloc() and mdiobus_free(), and makes all mdio bus drivers use these functions to allocate their struct mii_bus'es dynamically. Signed-off-by: Lennert Buytenhek <buytenh@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Andy Fleming <afleming@freescale.com>
Diffstat (limited to 'drivers/net/phy')
-rw-r--r--drivers/net/phy/fixed.c29
-rw-r--r--drivers/net/phy/mdio-bitbang.c4
-rw-r--r--drivers/net/phy/mdio-ofgpio.c9
-rw-r--r--drivers/net/phy/mdio_bus.c24
4 files changed, 49 insertions, 17 deletions
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 1cec8967a089..b5e13f8d5e31 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -24,7 +24,7 @@
24 24
25struct fixed_mdio_bus { 25struct fixed_mdio_bus {
26 int irqs[PHY_MAX_ADDR]; 26 int irqs[PHY_MAX_ADDR];
27 struct mii_bus mii_bus; 27 struct mii_bus *mii_bus;
28 struct list_head phys; 28 struct list_head phys;
29}; 29};
30 30
@@ -213,19 +213,27 @@ static int __init fixed_mdio_bus_init(void)
213 goto err_pdev; 213 goto err_pdev;
214 } 214 }
215 215
216 snprintf(fmb->mii_bus.id, MII_BUS_ID_SIZE, "0"); 216 fmb->mii_bus = mdiobus_alloc();
217 fmb->mii_bus.name = "Fixed MDIO Bus"; 217 if (fmb->mii_bus == NULL) {
218 fmb->mii_bus.parent = &pdev->dev; 218 ret = -ENOMEM;
219 fmb->mii_bus.read = &fixed_mdio_read; 219 goto err_mdiobus_reg;
220 fmb->mii_bus.write = &fixed_mdio_write; 220 }
221 fmb->mii_bus.irq = fmb->irqs;
222 221
223 ret = mdiobus_register(&fmb->mii_bus); 222 snprintf(fmb->mii_bus->id, MII_BUS_ID_SIZE, "0");
223 fmb->mii_bus->name = "Fixed MDIO Bus";
224 fmb->mii_bus->parent = &pdev->dev;
225 fmb->mii_bus->read = &fixed_mdio_read;
226 fmb->mii_bus->write = &fixed_mdio_write;
227 fmb->mii_bus->irq = fmb->irqs;
228
229 ret = mdiobus_register(fmb->mii_bus);
224 if (ret) 230 if (ret)
225 goto err_mdiobus_reg; 231 goto err_mdiobus_alloc;
226 232
227 return 0; 233 return 0;
228 234
235err_mdiobus_alloc:
236 mdiobus_free(fmb->mii_bus);
229err_mdiobus_reg: 237err_mdiobus_reg:
230 platform_device_unregister(pdev); 238 platform_device_unregister(pdev);
231err_pdev: 239err_pdev:
@@ -238,7 +246,8 @@ static void __exit fixed_mdio_bus_exit(void)
238 struct fixed_mdio_bus *fmb = &platform_fmb; 246 struct fixed_mdio_bus *fmb = &platform_fmb;
239 struct fixed_phy *fp, *tmp; 247 struct fixed_phy *fp, *tmp;
240 248
241 mdiobus_unregister(&fmb->mii_bus); 249 mdiobus_unregister(fmb->mii_bus);
250 mdiobus_free(fmb->mii_bus);
242 platform_device_unregister(pdev); 251 platform_device_unregister(pdev);
243 252
244 list_for_each_entry_safe(fp, tmp, &fmb->phys, node) { 253 list_for_each_entry_safe(fp, tmp, &fmb->phys, node) {
diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
index c01b78013ddc..2576055b350b 100644
--- a/drivers/net/phy/mdio-bitbang.c
+++ b/drivers/net/phy/mdio-bitbang.c
@@ -165,7 +165,7 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl)
165{ 165{
166 struct mii_bus *bus; 166 struct mii_bus *bus;
167 167
168 bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); 168 bus = mdiobus_alloc();
169 if (!bus) 169 if (!bus)
170 return NULL; 170 return NULL;
171 171
@@ -184,7 +184,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
184 struct mdiobb_ctrl *ctrl = bus->priv; 184 struct mdiobb_ctrl *ctrl = bus->priv;
185 185
186 module_put(ctrl->ops->owner); 186 module_put(ctrl->ops->owner);
187 kfree(bus); 187 mdiobus_free(bus);
188} 188}
189EXPORT_SYMBOL(free_mdio_bitbang); 189EXPORT_SYMBOL(free_mdio_bitbang);
190 190
diff --git a/drivers/net/phy/mdio-ofgpio.c b/drivers/net/phy/mdio-ofgpio.c
index 27bd4539d089..2ff97754e574 100644
--- a/drivers/net/phy/mdio-ofgpio.c
+++ b/drivers/net/phy/mdio-ofgpio.c
@@ -122,7 +122,7 @@ static int __devinit mdio_ofgpio_probe(struct of_device *ofdev,
122 122
123 new_bus = alloc_mdio_bitbang(&bitbang->ctrl); 123 new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
124 if (!new_bus) 124 if (!new_bus)
125 goto out_free_priv; 125 goto out_free_bitbang;
126 126
127 new_bus->name = "GPIO Bitbanged MII", 127 new_bus->name = "GPIO Bitbanged MII",
128 128
@@ -155,9 +155,9 @@ out_free_irqs:
155 dev_set_drvdata(&ofdev->dev, NULL); 155 dev_set_drvdata(&ofdev->dev, NULL);
156 kfree(new_bus->irq); 156 kfree(new_bus->irq);
157out_free_bus: 157out_free_bus:
158 kfree(new_bus);
159out_free_priv:
160 free_mdio_bitbang(new_bus); 158 free_mdio_bitbang(new_bus);
159out_free_bitbang:
160 kfree(bitbang);
161out: 161out:
162 return ret; 162 return ret;
163} 163}
@@ -168,11 +168,10 @@ static int mdio_ofgpio_remove(struct of_device *ofdev)
168 struct mdio_gpio_info *bitbang = bus->priv; 168 struct mdio_gpio_info *bitbang = bus->priv;
169 169
170 mdiobus_unregister(bus); 170 mdiobus_unregister(bus);
171 kfree(bus->irq);
171 free_mdio_bitbang(bus); 172 free_mdio_bitbang(bus);
172 dev_set_drvdata(&ofdev->dev, NULL); 173 dev_set_drvdata(&ofdev->dev, NULL);
173 kfree(bus->irq);
174 kfree(bitbang); 174 kfree(bitbang);
175 kfree(bus);
176 175
177 return 0; 176 return 0;
178} 177}
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index a7211a32bb4a..d206691f15d8 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -36,6 +36,18 @@
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37 37
38/** 38/**
39 * mdiobus_alloc - allocate a mii_bus structure
40 *
41 * Description: called by a bus driver to allocate an mii_bus
42 * structure to fill in.
43 */
44struct mii_bus *mdiobus_alloc(void)
45{
46 return kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
47}
48EXPORT_SYMBOL(mdiobus_alloc);
49
50/**
39 * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus 51 * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
40 * @bus: target mii_bus 52 * @bus: target mii_bus
41 * 53 *
@@ -87,6 +99,18 @@ void mdiobus_unregister(struct mii_bus *bus)
87} 99}
88EXPORT_SYMBOL(mdiobus_unregister); 100EXPORT_SYMBOL(mdiobus_unregister);
89 101
102/**
103 * mdiobus_free - free a struct mii_bus
104 * @bus: mii_bus to free
105 *
106 * This function frees the mii_bus.
107 */
108void mdiobus_free(struct mii_bus *bus)
109{
110 kfree(bus);
111}
112EXPORT_SYMBOL(mdiobus_free);
113
90struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) 114struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
91{ 115{
92 struct phy_device *phydev; 116 struct phy_device *phydev;