Re: [PATCH 6/6] of/device: populate platform_device (of_device) resource table on allocation

2 messages, 2 authors, 2010-06-10 · open the first message on its own page

Re: [PATCH 6/6] of/device: populate platform_device (of_device) resource table on allocation

From: Anton Vorontsov <hidden>
Date: 2010-06-10 17:10:29

On Thu, Jun 10, 2010 at 10:30:26AM -0600, Grant Likely wrote:
[...]
C)
struct of_device *alloc_function(int num_res)
{
	struct device *ofdev;
	struct resource *res;
	ofdev = kzalloc(sizeof(*ofdev), GFP_KERNEL)
	if (!ofdev)
		return NULL;
	res = kzalloc((sizeof(*res) * num_res), GFP_KERNEL);
	if (!res) {
		kfree(ofdev);  /* or goto an error unwind label */
		return NULL;
	}
	res = (struct resource *)&ofdev[1];
You mean ofdev->resource = res; ?
That being said, I'm looking at refactoring to use
platform_device_alloc() instead, which is effectively option C. (which
I'd normally avoid, but it removes otherwise duplicate code from
drivers/of).
Sounds great!

Thanks,

-- 
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2

Re: [PATCH 6/6] of/device: populate platform_device (of_device) resource table on allocation

From: Grant Likely <hidden>
Date: 2010-06-10 17:21:16

On Thu, Jun 10, 2010 at 11:10 AM, Anton Vorontsov
[off-list ref] wrote:
On Thu, Jun 10, 2010 at 10:30:26AM -0600, Grant Likely wrote:
[...]
quoted
=A0 =A0 =A0 res =3D kzalloc((sizeof(*res) * num_res), GFP_KERNEL);
=A0 =A0 =A0 if (!res) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 kfree(ofdev); =A0/* or goto an error unwind =
label */
quoted
=A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
=A0 =A0 =A0 }
=A0 =A0 =A0 res =3D (struct resource *)&ofdev[1];
You mean ofdev->resource =3D res; ?
Yeah, cut-and-paste error.

g.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help