All of lore.kernel.org
 help / color / mirror / Atom feed
From: Timur Tabi <timur@freescale.com>
To: Andy Fleming <afleming@freescale.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, linuxppc-dev@ozlabs.org
Subject: Re: [PATCH] phylib: update mdiobus_alloc() to allocate extra private space
Date: Thu, 15 Dec 2011 11:12:01 -0600	[thread overview]
Message-ID: <4EEA2A61.8050302@freescale.com> (raw)
In-Reply-To: <8ABCAC4C-1D11-41AD-AE46-96EB9D40588D@freescale.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: Timur Tabi <timur@freescale.com>
To: Andy Fleming <afleming@freescale.com>
Cc: <davem@davemloft.net>, <netdev@vger.kernel.org>,
	<linuxppc-dev@ozlabs.org>
Subject: Re: [PATCH] phylib: update mdiobus_alloc() to allocate extra private space
Date: Thu, 15 Dec 2011 11:12:01 -0600	[thread overview]
Message-ID: <4EEA2A61.8050302@freescale.com> (raw)
In-Reply-To: <8ABCAC4C-1D11-41AD-AE46-96EB9D40588D@freescale.com>

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

  reply	other threads:[~2011-12-15 17:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15 16:51 [PATCH] phylib: update mdiobus_alloc() to allocate extra private space Timur Tabi
2011-12-15 17:06 ` Andy Fleming
2011-12-15 17:06   ` Andy Fleming
2011-12-15 17:12   ` Timur Tabi [this message]
2011-12-15 17:12     ` Timur Tabi
2011-12-16 20:32     ` David Miller
2011-12-16 20:32       ` David Miller
2011-12-16 20:37       ` Timur Tabi
2011-12-16 20:37         ` Timur Tabi
2011-12-16 20:31 ` David Miller
2011-12-16 20:31   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EEA2A61.8050302@freescale.com \
    --to=timur@freescale.com \
    --cc=afleming@freescale.com \
    --cc=davem@davemloft.net \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.