linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ryan@bluewatersys.com (Ryan Mallon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 02/23] at91: Make Ethernet device common
Date: Fri, 29 Apr 2011 21:38:36 +1200	[thread overview]
Message-ID: <4DBA871C.1030007@bluewatersys.com> (raw)
In-Reply-To: <20110429090809.GY17290@n2100.arm.linux.org.uk>

On 29/04/11 21:08, Russell King - ARM Linux wrote:
> On Fri, Apr 29, 2011 at 02:59:11PM +1200, Ryan Mallon wrote:
>> +#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
>> +static u64 eth_dmamask = DMA_BIT_MASK(32);
>> +static struct at91_eth_data eth_data;
>> +
>> +static struct resource eth_resources[] = {
>> +	[0] = {
>> +		.end	= SZ_16K,
>> +		.flags	= IORESOURCE_MEM,
>> +	},
>> +	[1] = {
>> +		.flags	= IORESOURCE_IRQ,
>> +	},
>> +};
>> +
>> +static struct platform_device at91_eth_device = {
>> +	.name		= "macb",
>> +	.id		= -1,
>> +	.dev		= {
>> +				.dma_mask		= &eth_dmamask,
>> +				.coherent_dma_mask	= DMA_BIT_MASK(32),
>> +				.platform_data		= &eth_data,
> 
> These three lines have twice as many tabs as is needed.

Hartley pointed this out also. The reason it is this way is because I
cut and pasted the code from one of the existing implementations (to
make the changeset minimal). I can fix this if preferred.

> 
>> +	},
>> +	.resource	= eth_resources,
>> +	.num_resources	= ARRAY_SIZE(eth_resources),
>> +};
>> +
>> +void __init at91_add_device_eth(struct at91_eth_data *data)
>> +{
>> +	struct at91_dev_table_ethernet *info = devices->ethernet;
>> +
>> +	BUG_ON(!info);
>> +	init_resource_mem(&eth_resources[0], info->mmio_base);
>> +	init_resource_irq(&eth_resources[1], info->irq);
> 
> Hmm.  How about something like this instead:
> 
> 	struct resource eth_res[2];
> 	int err;
> 
> 	BUG_ON(!info);
> 
> 	init_resource_mem(&eth_res[0], info->mmio_base, SZ_16K);
> 	init_resource_irq(&eth_res[1], info->irq);
> 
> 	...
> 
> 	err = platform_device_add_resources(&at91_eth_device, eth_res, 2);
> 	if (err) {
> 		pr_err("eth: unable to add resources: %d\n", err);
> 		return;
> 	}
> 
> 	err = platform_device_add_data(&at91_eth_device, data, sizeof(*data));
> 	if (err) {
> 		pr_err("eth: unable to add platform data: %d\n", err);
> 		/* res leaked */
> 		return;
> 	}
> 
> 	err = platform_device_register(&at91_eth_device);
> 	if (err) {
> 		pr_err("eth: unable to register device: %d\n", err);
> 		/* res and data leaked */
> 	}
> 
> With Uwe's patches, we can plug those leaks.  Note that we can't use
> platform_device_register_resndata() because it doesn't set the DMA
> masks etc (which is one of the problems I've always had with interfaces
> which try to wrap too much stuff up - they always lack something.)
> 
> This would get rid of the need to have the resources and platform
> data storage declared for each and every device.  I'd suggest wrapping
> the last bit adding the platform data and resources up in its own
> function common to each device as its going to be the same for
> everything.  Remember to pass the size of the platform data though.

That seems sensible. It should be possible to make the whole lot
generic. i.e.

static void __init add_device(struct device *dev, struct resource *res,
				int nr_res, void *data,
				size_t data_size)
{
	if (res) {
 		err = platform_device_add_resources(dev, res, nr_res);
 		if (err) {
 			pr_err("eth: unable to add resources: %d\n", err);
 			return;
 		}
	}

	if (data) {
 		err = platform_device_add_data(dev, data, data_size);
 		if (err) {
 			pr_err("eth: unable to add platform data: %d\n", err);
 			/* res leaked */
 			return;
 		}
	}

 	err = platform_device_register(dev);
 	if (err) {
 		pr_err("eth: unable to register device: %d\n", err);
 		/* res and data leaked */
 	}	
}

void __init at91_add_device_eth(struct at91_eth_data *data)
{
	struct at91_dev_table_ethernet *info = devices->ethernet;
	struct resource res[2];

	BUG_ON(!info);
	init_resource_mem(&res[0], info->mmio_base, SZ_16K);
	init_resource_irq(&res[1], info->irq);
	add_device(&at91_eth_device, res, ARRAY_SIZE(res),
			 data, sizeof(*data));
}

Is this what you mean?

~Ryan

  reply	other threads:[~2011-04-29  9:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-29  2:59 [PATCH v3 00/23] Create common framework for AT91 device initialisation Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 01/23] at91: Add common devices framework Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 02/23] at91: Make Ethernet device common Ryan Mallon
2011-04-29  9:08   ` Russell King - ARM Linux
2011-04-29  9:38     ` Ryan Mallon [this message]
2011-04-29  9:54       ` Russell King - ARM Linux
2011-04-29  2:59 ` [PATCH v3 03/23] at91: Make USB OHCI/EHCI devices common Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 04/23] at91: Make UDC device common Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 05/23] at91: Make MMC " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 06/23] at91: Make NAND " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 07/23] at91: Make TWI " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 08/23] at91: Make SPI " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 09/23] at91: Make TCB " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 10/23] at91: Make RTT " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 11/23] at91: Make watchdog " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 12/23] at91: Make UART devices common Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 13/23] at91: Make PWM device common Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 14/23] at91: Make SSC " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 15/23] at91: Make AC97 " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 16/23] at91: Make LCD controller " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 17/23] at91: Make touchscreen " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 18/23] at91: Make HDMAC " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 19/23] at91: Make RTC " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 20/23] at91: Make high speed USB gadget " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 21/23] at91: Make compact flash " Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 22/23] at91: Move at91sam9263 CAN device to common devices Ryan Mallon
2011-04-29  2:59 ` [PATCH v3 23/23] at91: Remove mAgic and ISI device code Ryan Mallon
2011-04-29 18:04 ` [PATCH v3 00/23] Create common framework for AT91 device initialisation H Hartley Sweeten
2011-04-29 20:14   ` Ryan Mallon
2011-05-02 19:46     ` Jean-Christophe PLAGNIOL-VILLARD

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=4DBA871C.1030007@bluewatersys.com \
    --to=ryan@bluewatersys.com \
    --cc=linux-arm-kernel@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).