Skip to contentSkip to conversation

pinctrl: st: constify gpio_chip structure

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

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

PATCH 1/1 pinctrl: st: 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
  21671    3632     128   25431    6357 drivers/pinctrl/pinctrl-st.o

after:

   text    data     bss     dec     hex filename
  21366    3576     128   25070    61ee drivers/pinctrl/pinctrl-st.o
---
 drivers/pinctrl/pinctrl-st.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-st.c +1 -1
index 3ae8066..5d4789d 100644
@@ -1442,7 +1442,7 @@ static void st_gpio_irqmux_handler(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
-static struct gpio_chip st_gpio_template = {
+static const struct gpio_chip st_gpio_template = {
 	.request		= gpiochip_generic_request,
 	.free			= gpiochip_generic_free,
 	.get			= st_gpio_get,
Signature · 1 line
2.5.0
Acked-by on v1 1/1
#1 lore raw

Hi Gustavo

Quoted 55 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:

    text    data     bss     dec     hex filename
   21671    3632     128   25431    6357 drivers/pinctrl/pinctrl-st.o

after:

    text    data     bss     dec     hex filename
   21366    3576     128   25070    61ee drivers/pinctrl/pinctrl-st.o
---
  drivers/pinctrl/pinctrl-st.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-st.c +0 -0
index 3ae8066..5d4789d 100644

drivers/pinctrl/pinctrl-st.c static void st_gpio_irqmux_handler(struct irq_desc *desc) · line 1448

Quoted 8 lines
drivers/pinctrl/pinctrl-st.c +1 -1
@@ -1442,7 +1442,7 @@ static void st_gpio_irqmux_handler(struct irq_desc *desc)
  	chained_irq_exit(chip, desc);
  }
 
-static struct gpio_chip st_gpio_template = {
+static const struct gpio_chip st_gpio_template = {
  	.request		= gpiochip_generic_request,
  	.free			= gpiochip_generic_free,
  	.get			= st_gpio_get,

Thanks

#2 lore raw

Hi Patrice,

Quoting Patrice CHOTARD <[email protected]>:

Quoted 70 lines

Hi Gustavo

Quoted 62 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:

    text    data     bss     dec     hex filename
   21671    3632     128   25431    6357 drivers/pinctrl/pinctrl-st.o

after:

    text    data     bss     dec     hex filename
   21366    3576     128   25070    61ee drivers/pinctrl/pinctrl-st.o
---
  drivers/pinctrl/pinctrl-st.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-st.c +1 -1
index 3ae8066..5d4789d 100644
@@ -1442,7 +1442,7 @@ static void st_gpio_irqmux_handler(struct  
 irq_desc *desc)
  	chained_irq_exit(chip, desc);
  }
 
-static struct gpio_chip st_gpio_template = {
+static const struct gpio_chip st_gpio_template = {
  	.request		= gpiochip_generic_request,
  	.free			= gpiochip_generic_free,
Quoted 2 lines

.get = st_gpio_get,

Quoted 1 line

Thanks

Glad to help. :)

Thanks
--
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
  21671    3632     128   25431    6357 drivers/pinctrl/pinctrl-st.o

after:

   text    data     bss     dec     hex filename
  21366    3576     128   25070    61ee drivers/pinctrl/pinctrl-st.o

Patch applied with Patrice's ACK.

Yours,
Linus Walleij