linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: bcm2835: constify gpio_chip structure
@ 2017-07-11 18:03 Gustavo A. R. Silva
  2017-07-12 19:13 ` Eric Anholt
  2017-08-02  8:25 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-11 18:03 UTC (permalink / raw)
  To: Linus Walleij, Florian Fainelli, Ray Jui, Scott Branden,
	Eric Anholt, Stefan Wahren
  Cc: bcm-kernel-feedback-list, linux-gpio, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, Gustavo A. R. Silva

This structure is only used to copy into other structure, so declare
it as const.

This issue was detected using Coccinelle and the following semantic patch:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct gpio_chip i@p = { ... };

@ok@
identifier r.i;
expression e;
position p;
@@
e = i@p;

@bad@
position p != {r.p,ok.p};
identifier r.i;
struct gpio_chip e;
@@
e@i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
 struct gpio_chip i = { ... };

In the following log you can see a significant difference in the code size
and data segment, hence in the dec segment. This log is the output
of the size command, before and after the code change:

before:
   text    data     bss     dec     hex filename
  18958    9000     128   28086    6db6 drivers/pinctrl/bcm/pinctrl-bcm2835.o

after:
   text    data     bss     dec     hex filename
  18764    8912     128   27804    6c9c drivers/pinctrl/bcm/pinctrl-bcm2835.o

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
index 2308831..7203f35 100644
--- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
@@ -353,7 +353,7 @@ static int bcm2835_gpio_direction_output(struct gpio_chip *chip,
 	return pinctrl_gpio_direction_output(chip->base + offset);
 }
 
-static struct gpio_chip bcm2835_gpio_chip = {
+static const struct gpio_chip bcm2835_gpio_chip = {
 	.label = MODULE_NAME,
 	.owner = THIS_MODULE,
 	.request = gpiochip_generic_request,
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: bcm2835: constify gpio_chip structure
  2017-07-11 18:03 [PATCH] pinctrl: bcm2835: constify gpio_chip structure Gustavo A. R. Silva
@ 2017-07-12 19:13 ` Eric Anholt
  2017-07-17  4:12   ` Gustavo A. R. Silva
  2017-08-02  8:25 ` Linus Walleij
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Anholt @ 2017-07-12 19:13 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Linus Walleij, Florian Fainelli, Ray Jui,
	Scott Branden, Stefan Wahren
  Cc: bcm-kernel-feedback-list, linux-gpio, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, Gustavo A. R. Silva

[-- Attachment #1: Type: text/plain, Size: 984 bytes --]

"Gustavo A. R. Silva" <garsilva@embeddedor.com> writes:

> This structure is only used to copy into other structure, so declare
> it as const.
>
> This issue was detected using Coccinelle and the following semantic patch:

Acked-by: Eric Anholt <eric@anholt.net>

> ---
>  drivers/pinctrl/bcm/pinctrl-bcm2835.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> index 2308831..7203f35 100644
> --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> @@ -353,7 +353,7 @@ static int bcm2835_gpio_direction_output(struct gpio_chip *chip,
>  	return pinctrl_gpio_direction_output(chip->base + offset);
>  }
>  
> -static struct gpio_chip bcm2835_gpio_chip = {
> +static const struct gpio_chip bcm2835_gpio_chip = {
>  	.label = MODULE_NAME,
>  	.owner = THIS_MODULE,
>  	.request = gpiochip_generic_request,
> -- 
> 2.5.0

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: bcm2835: constify gpio_chip structure
  2017-07-12 19:13 ` Eric Anholt
@ 2017-07-17  4:12   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-17  4:12 UTC (permalink / raw)
  To: Eric Anholt, Linus Walleij, Florian Fainelli, Ray Jui,
	Scott Branden, Stefan Wahren
  Cc: bcm-kernel-feedback-list, linux-gpio, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel



On 07/12/2017 02:13 PM, Eric Anholt wrote:
> "Gustavo A. R. Silva" <garsilva@embeddedor.com> writes:
>
>> This structure is only used to copy into other structure, so declare
>> it as const.
>>
>> This issue was detected using Coccinelle and the following semantic patch:
> Acked-by: Eric Anholt <eric@anholt.net>

Thank you, Eric

>> ---
>>   drivers/pinctrl/bcm/pinctrl-bcm2835.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>> index 2308831..7203f35 100644
>> --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>> +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>> @@ -353,7 +353,7 @@ static int bcm2835_gpio_direction_output(struct gpio_chip *chip,
>>   	return pinctrl_gpio_direction_output(chip->base + offset);
>>   }
>>   
>> -static struct gpio_chip bcm2835_gpio_chip = {
>> +static const struct gpio_chip bcm2835_gpio_chip = {
>>   	.label = MODULE_NAME,
>>   	.owner = THIS_MODULE,
>>   	.request = gpiochip_generic_request,
>> -- 
>> 2.5.0

-- 
Gustavo A. R. Silva

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: bcm2835: constify gpio_chip structure
  2017-07-11 18:03 [PATCH] pinctrl: bcm2835: constify gpio_chip structure Gustavo A. R. Silva
  2017-07-12 19:13 ` Eric Anholt
@ 2017-08-02  8:25 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2017-08-02  8:25 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Florian Fainelli, Ray Jui, Scott Branden, Eric Anholt,
	Stefan Wahren, bcm-kernel-feedback-list, linux-gpio,
	linux-rpi-kernel, linux-arm-kernel, linux-kernel

On Tue, Jul 11, 2017 at 8:03 PM, Gustavo A. R. Silva
<garsilva@embeddedor.com> wrote:

> This structure is only used to copy into other structure, so declare
> it as const.
>
> This issue was detected using Coccinelle and the following semantic patch:
>
> @r disable optional_qualifier@
> identifier i;
> position p;
> @@
> static struct gpio_chip i@p = { ... };
>
> @ok@
> identifier r.i;
> expression e;
> position p;
> @@
> e = i@p;
>
> @bad@
> position p != {r.p,ok.p};
> identifier r.i;
> struct gpio_chip e;
> @@
> e@i@p
>
> @depends on !bad disable optional_qualifier@
> identifier r.i;
> @@
> static
> +const
>  struct gpio_chip i = { ... };
>
> In the following log you can see a significant difference in the code size
> and data segment, hence in the dec segment. This log is the output
> of the size command, before and after the code change:
>
> before:
>    text    data     bss     dec     hex filename
>   18958    9000     128   28086    6db6 drivers/pinctrl/bcm/pinctrl-bcm2835.o
>
> after:
>    text    data     bss     dec     hex filename
>   18764    8912     128   27804    6c9c drivers/pinctrl/bcm/pinctrl-bcm2835.o
>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>

Patch applied with Eric's ACK.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-08-02  8:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-11 18:03 [PATCH] pinctrl: bcm2835: constify gpio_chip structure Gustavo A. R. Silva
2017-07-12 19:13 ` Eric Anholt
2017-07-17  4:12   ` Gustavo A. R. Silva
2017-08-02  8:25 ` Linus Walleij

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).