Skip to contentSkip to conversation

pinctrl: bcm2835: constify gpio_chip structure

PATCH In review Gustavo A. R. Silva 3 participants 4 messages Jul 11, 2017 – Aug 2, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: bcm2835: constify gpio_chip structure

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 at p = { ... };

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

@bad@
position p != {r.p,ok.p};
identifier r.i;
struct gpio_chip e;
@@
e at 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
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/bcm/pinctrl-bcm2835.c +1 -1
index 2308831..7203f35 100644
@@ -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,
Signature · 1 line
2.5.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · 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:

Quoted 19 lines
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/bcm/pinctrl-bcm2835.c +1 -1
index 2308831..7203f35 100644
@@ -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,
Signature · 1 line
2.5.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170712/1e036ba0/attachment.sig>

#2 lore raw
Quoted 7 lines · Eric Anholt
Quoted 4 lines · 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:

Thank you, Eric

Quoted 19 lines
Quoted 19 lines
---
  drivers/pinctrl/bcm/pinctrl-bcm2835.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/bcm/pinctrl-bcm2835.c +1 -1
index 2308831..7203f35 100644
@@ -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,
Signature · 1 line
2.5.0
Signature · 1 line
Gustavo A. R. Silva
#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 37 lines · 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 at p = { ... };

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

@bad@
position p != {r.p,ok.p};
identifier r.i;
struct gpio_chip e;
@@
e at 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:

Quoted 8 lines
   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

Patch applied with Eric's ACK.

Yours,
Linus Walleij