aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimur Tabi <timur@freescale.com>2012-01-12 18:23:04 -0500
committerDavid S. Miller <davem@davemloft.net>2012-01-12 18:23:04 -0500
commiteb8a54a78e974e1af3e17fa38bb74d3747c5c1bd (patch)
treed3642783d7470c26815b7d3c14ea5d5949d7dcdb
parent1398eee08222a038fa5f017900f387e81f6e3ff4 (diff)
phylib: introduce mdiobus_alloc_size()
Introduce function mdiobus_alloc_size() as an alternative to mdiobus_alloc(). Most callers of mdiobus_alloc() also allocate a private data structure, and then manually point bus->priv to this object. mdiobus_alloc_size() combines the two operations into one, which simplifies memory management. The original mdiobus_alloc() now just calls mdiobus_alloc_size(0). Signed-off-by: Timur Tabi <timur@freescale.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/phy/mdio_bus.c24
-rw-r--r--include/linux/phy.h7
2 files changed, 25 insertions, 6 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6c58da2b882c..88cc5db9affd 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -37,22 +37,36 @@
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38 38
39/** 39/**
40 * mdiobus_alloc - allocate a mii_bus structure 40 * mdiobus_alloc_size - allocate a mii_bus structure
41 * 41 *
42 * Description: called by a bus driver to allocate an mii_bus 42 * Description: called by a bus driver to allocate an mii_bus
43 * structure to fill in. 43 * structure to fill in.
44 *
45 * 'size' is an an extra amount of memory to allocate for private storage.
46 * If non-zero, then bus->priv is points to that memory.
44 */ 47 */
45struct mii_bus *mdiobus_alloc(void) 48struct mii_bus *mdiobus_alloc_size(size_t size)
46{ 49{
47 struct mii_bus *bus; 50 struct mii_bus *bus;
51 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN);
52 size_t alloc_size;
53
54 /* If we alloc extra space, it should be aligned */
55 if (size)
56 alloc_size = aligned_size + size;
57 else
58 alloc_size = sizeof(*bus);
48 59
49 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 60 bus = kzalloc(alloc_size, GFP_KERNEL);
50 if (bus != NULL) 61 if (bus) {
51 bus->state = MDIOBUS_ALLOCATED; 62 bus->state = MDIOBUS_ALLOCATED;
63 if (size)
64 bus->priv = (void *)bus + aligned_size;
65 }
52 66
53 return bus; 67 return bus;
54} 68}
55EXPORT_SYMBOL(mdiobus_alloc); 69EXPORT_SYMBOL(mdiobus_alloc_size);
56 70
57/** 71/**
58 * mdiobus_release - mii_bus device release callback 72 * mdiobus_release - mii_bus device release callback
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 79f337c47388..c599f7eca1e7 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -129,7 +129,12 @@ struct mii_bus {
129}; 129};
130#define to_mii_bus(d) container_of(d, struct mii_bus, dev) 130#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
131 131
132struct mii_bus *mdiobus_alloc(void); 132struct mii_bus *mdiobus_alloc_size(size_t);
133static inline struct mii_bus *mdiobus_alloc(void)
134{
135 return mdiobus_alloc_size(0);
136}
137
133int mdiobus_register(struct mii_bus *bus); 138int mdiobus_register(struct mii_bus *bus);
134void mdiobus_unregister(struct mii_bus *bus); 139void mdiobus_unregister(struct mii_bus *bus);
135void mdiobus_free(struct mii_bus *bus); 140void mdiobus_free(struct mii_bus *bus);