devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>
To: Alexander Shiyan <shc_work-JGs/UdohzUI@public.gmane.org>
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH 1/2] GPIO: clps711x: Rewrite driver for using generic GPIO code
Date: Thu, 25 Apr 2013 12:40:41 +0100	[thread overview]
Message-ID: <20130425114041.GC14496@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1366889467.845096985-i8J/Zv46+dgedp2WBT/QOw@public.gmane.org>

On Thu, Apr 25, 2013 at 03:31:07PM +0400, Alexander Shiyan wrote:
> > On Sat, Apr 13, 2013 at 08:21:39AM +0400, Alexander Shiyan wrote:
> > > +static void __init clps711x_add_gpio(void)
> > > +{
> > > +	const struct resource clps711x_gpio0_res[] = {
> > > +		DEFINE_RES_MEM(PADR, SZ_1),
> > > +		DEFINE_RES_MEM(PADDR, SZ_1),
> > > +	};
> ...
> > Don't do this - this is incredibly wasteful.
> > 
> > C lesson 1: do not put unmodified initialised structures onto the stack.
> > 
> > What the C compiler will do with the above is exactly the same as this
> > for each structure:
> > 
> > static const struct resource private_clps711x_gpio4_res[] = {
> > 	DEFINE_RES_MEM(PEDR, SZ_1),
> > 	DEFINE_RES_MEM(PEDDR, SZ_1),
> > };
> > 
> > static void __init clps711x_add_gpio(void)
> > {
> > 	const struct resource clps711x_gpio4_res[] = private_clps711x_gpio4_res;
> > 	...
> > 
> > which will in itself be a call out to memcpy, or an inlined memcpy.  Now
> > do you see why it's wasteful?  You might as well write the thing in that
> > way to start with and safe the additional code to copy the structures.
> > 
> > The other way to do this, which will probably be far more space efficient:
> > 
> > static phys_addr_t gpio_addrs[][2] = {
> > 	{ PADR, PADDR },
> > 	{ PBDR, PBDDR },
> > ...
> > };
> > 
> > static void __init clps711x_add_gpio(void)
> > {
> > 	struct resource gpio_res[2];
> > 	unsigned i;
> > 
> > 	gpio_res[0].flags = IORESOURCE_MEM;
> > 	gpio_res[1].flags = IORESOURCE_MEM;
> > 
> > 	for (i = 0; i < ARRAY_SIZE(gpio_addrs); i++) {
> > 		gpio_res[0].start = gpio_addrs[i][0];
> > 		gpio_res[0].end = gpio_res[0].start;
> > 		gpio_res[1].start = gpio_addrs[i][1];
> > 		gpio_res[1].end = gpio_res[1].start;
> > 
> > 		platform_device_register_simple("clps711x-gpio", i,
> > 					gpio_res, ARRAY_SIZE(gpio_res));
> > 	}
> > }
> > 
> > which results in smaller storage and most probably also smaller code size
> > too.
> 
> Very strange results with this change.
> So, I add a debug output before "platform_device_register_simple" for
> print resource and in "__request_resource" for print parent.
> This is output.
> gpio 0 [mem 0x80000000] [mem 0x80000040]
> resource: root [??? 0xe3a0f000-0x00000000 flags 0xb00000]
> clps711x-gpio.0: failed to claim resource 0
> 
> The first line is seems correct. But I do not understand why
> parent is wrong here. Normally it should be as:
> resource: root [mem 0x00000000-0xffffffff].
> And it shows normal with my first version.
> Have anyone any ideas?

memset(&gpio_res, 0, sizeof(gpio_res));

      parent reply	other threads:[~2013-04-25 11:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-13  4:21 [PATCH 1/2] GPIO: clps711x: Rewrite driver for using generic GPIO code Alexander Shiyan
     [not found] ` <1365826900-30136-1-git-send-email-shc_work-JGs/UdohzUI@public.gmane.org>
2013-04-13  4:21   ` [PATCH 2/2] GPIO: clps711x: Add DT support Alexander Shiyan
2013-04-15  3:33 ` [PATCH 1/2] GPIO: clps711x: Rewrite driver for using generic GPIO code Olof Johansson
2013-04-15  7:13   ` Re[2]: " Alexander Shiyan
2013-04-19 14:03 ` Russell King - ARM Linux
     [not found]   ` <20130419140357.GR14496-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2013-04-20  9:16     ` Re[2]: " Alexander Shiyan
2013-04-25 11:31     ` Alexander Shiyan
     [not found]       ` <1366889467.845096985-i8J/Zv46+dgedp2WBT/QOw@public.gmane.org>
2013-04-25 11:40         ` Russell King - ARM Linux [this message]

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=20130425114041.GC14496@n2100.arm.linux.org.uk \
    --to=linux-lfz/pmaqli7xmaaqvzeohq@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
    --cc=shc_work-JGs/UdohzUI@public.gmane.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).