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>
This commit is contained in:
parent
1398eee082
commit
eb8a54a78e
@ -37,22 +37,36 @@
|
|||||||
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mdiobus_alloc - allocate a mii_bus structure
|
* mdiobus_alloc_size - allocate a mii_bus structure
|
||||||
*
|
*
|
||||||
* Description: called by a bus driver to allocate an mii_bus
|
* Description: called by a bus driver to allocate an mii_bus
|
||||||
* structure to fill in.
|
* structure to fill in.
|
||||||
|
*
|
||||||
|
* 'size' is an an extra amount of memory to allocate for private storage.
|
||||||
|
* If non-zero, then bus->priv is points to that memory.
|
||||||
*/
|
*/
|
||||||
struct mii_bus *mdiobus_alloc(void)
|
struct mii_bus *mdiobus_alloc_size(size_t size)
|
||||||
{
|
{
|
||||||
struct mii_bus *bus;
|
struct mii_bus *bus;
|
||||||
|
size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN);
|
||||||
|
size_t alloc_size;
|
||||||
|
|
||||||
bus = kzalloc(sizeof(*bus), GFP_KERNEL);
|
/* If we alloc extra space, it should be aligned */
|
||||||
if (bus != NULL)
|
if (size)
|
||||||
|
alloc_size = aligned_size + size;
|
||||||
|
else
|
||||||
|
alloc_size = sizeof(*bus);
|
||||||
|
|
||||||
|
bus = kzalloc(alloc_size, GFP_KERNEL);
|
||||||
|
if (bus) {
|
||||||
bus->state = MDIOBUS_ALLOCATED;
|
bus->state = MDIOBUS_ALLOCATED;
|
||||||
|
if (size)
|
||||||
|
bus->priv = (void *)bus + aligned_size;
|
||||||
|
}
|
||||||
|
|
||||||
return bus;
|
return bus;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(mdiobus_alloc);
|
EXPORT_SYMBOL(mdiobus_alloc_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mdiobus_release - mii_bus device release callback
|
* mdiobus_release - mii_bus device release callback
|
||||||
|
@ -129,7 +129,12 @@ struct mii_bus {
|
|||||||
};
|
};
|
||||||
#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
|
#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
|
||||||
|
|
||||||
struct mii_bus *mdiobus_alloc(void);
|
struct mii_bus *mdiobus_alloc_size(size_t);
|
||||||
|
static inline struct mii_bus *mdiobus_alloc(void)
|
||||||
|
{
|
||||||
|
return mdiobus_alloc_size(0);
|
||||||
|
}
|
||||||
|
|
||||||
int mdiobus_register(struct mii_bus *bus);
|
int mdiobus_register(struct mii_bus *bus);
|
||||||
void mdiobus_unregister(struct mii_bus *bus);
|
void mdiobus_unregister(struct mii_bus *bus);
|
||||||
void mdiobus_free(struct mii_bus *bus);
|
void mdiobus_free(struct mii_bus *bus);
|
||||||
|
Loading…
Reference in New Issue
Block a user