Thread (6 messages) flat view 6 messages, 3 authors, 2011-12-16

Re: [PATCH] phylib: update mdiobus_alloc() to allocate extra private space

From: Timur Tabi <hidden>
Date: 2011-12-15 17:23:46
Also in: netdev

Andy Fleming wrote:
Why? Doesn't this just obfuscate things a little, while providing no immediate benefit?
I see code like this frequently:

	bus = mdiobus_alloc();
	if (bus == NULL)
		return -ENOMEM;
	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (priv == NULL) {
		err = -ENOMEM;
		goto out_free;
	}
	bus->priv = priv;

This can be replaced with:

	bus = mdiobus_alloc(sizeof(*priv));
	if (bus == NULL)
		return -ENOMEM;

So the benefit is in simplifying memory management.  Now you have only one allocation to manage, instead of two.

fbdev does the same thing, which is where I got the idea from.  See framebuffer_alloc().

-- 
Timur Tabi
Linux kernel developer at Freescale
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help