* [PATCH] phylib: introduce mdiobus_alloc_size()
@ 2012-01-06 19:08 Timur Tabi
2012-01-12 23:23 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Timur Tabi @ 2012-01-06 19:08 UTC (permalink / raw)
To: afleming, davem, netdev
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>
---
drivers/net/phy/mdio_bus.c | 24 +++++++++++++++++++-----
include/linux/phy.h | 7 ++++++-
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6c58da2..88cc5db 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -37,22 +37,36 @@
#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
* 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;
+ size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN);
+ size_t alloc_size;
+
+ /* If we alloc extra space, it should be aligned */
+ if (size)
+ alloc_size = aligned_size + size;
+ else
+ alloc_size = sizeof(*bus);
- bus = kzalloc(sizeof(*bus), GFP_KERNEL);
- if (bus != NULL)
+ bus = kzalloc(alloc_size, GFP_KERNEL);
+ if (bus) {
bus->state = MDIOBUS_ALLOCATED;
+ if (size)
+ bus->priv = (void *)bus + aligned_size;
+ }
return bus;
}
-EXPORT_SYMBOL(mdiobus_alloc);
+EXPORT_SYMBOL(mdiobus_alloc_size);
/**
* mdiobus_release - mii_bus device release callback
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 79f337c..c599f7ec 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -129,7 +129,12 @@ struct mii_bus {
};
#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);
void mdiobus_unregister(struct mii_bus *bus);
void mdiobus_free(struct mii_bus *bus);
--
1.7.3.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] phylib: introduce mdiobus_alloc_size()
2012-01-06 19:08 [PATCH] phylib: introduce mdiobus_alloc_size() Timur Tabi
@ 2012-01-12 23:23 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2012-01-12 23:23 UTC (permalink / raw)
To: timur; +Cc: afleming, netdev
From: Timur Tabi <timur@freescale.com>
Date: Fri, 6 Jan 2012 13:08:33 -0600
> 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>
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-12 23:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-06 19:08 [PATCH] phylib: introduce mdiobus_alloc_size() Timur Tabi
2012-01-12 23:23 ` David Miller
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.