linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] account for const type of of_device_id.data
@ 2018-01-02 13:27 Julia Lawall
  2018-01-02 13:27 ` [PATCH 02/12] pinctrl: at91-pio4: " Julia Lawall
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Julia Lawall @ 2018-01-02 13:27 UTC (permalink / raw)
  To: linux-iio
  Cc: kernel-janitors, Peter Meerwald-Stadler, Lars-Peter Clausen,
	Hartmut Knaack, linux-mtd, linux-i2c, linux-spi, linux-rockchip,
	linux-arm-kernel, linux-pm, linux-kernel, linux-gpio, linux-pci,
	linux-arm-msm

Maintain const annotations when putting values into the data field of
an of_device_id structure, and afterwards when extracting them from
the data field of such a structure.

This was done using the following semantic patch:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier i,j;
const struct j *m;
struct i *y;
type T;
expression x,e;
position p;
@@

(
y =@p (T)(of_device_get_match_data(...));
|
x = of_match_node(...);
... when != x = e
(
m = e;
|
y =@p (T)(x->data);
)
)

@s@
identifier r.i,j;
@@

const struct i j = { ... };

@t depends on s disable optional_qualifier@
expression e;
identifier r.i,x,j,n;
struct j *m;
struct i *e1;
position any r.p;
type T;
@@

(
+const
struct i *x;
<+...
(
x =@p 
-   (T)(e)
+   e
|
x =@p e
)
...+>
|
m->@e1 n =@p 
-   (T)(e)
+   e
|
m->@e1 n =@p e
)

@disable optional_qualifier@
identifier t.j,t.n,r.i;
@@

struct j {
  ...
+ const
  struct i *n;
  ...
}

@@
identifier x,s.j;
type T;
@@

struct of_device_id x[] = { ...,
  { .data =
-           (T)
            &j, }, ...};

// </smpl>

---

 drivers/i2c/busses/i2c-rk3x.c               |   16 ++++++++--------
 drivers/iio/common/ssp_sensors/ssp.h        |    2 +-
 drivers/iio/common/ssp_sensors/ssp_dev.c    |    2 +-
 drivers/mtd/spi-nor/fsl-quadspi.c           |    8 ++++----
 drivers/pci/dwc/pcie-qcom.c                 |    4 ++--
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c |    4 ++--
 drivers/pinctrl/pinctrl-at91-pio4.c         |    4 ++--
 drivers/pinctrl/pinctrl-axp209.c            |    2 +-
 drivers/power/avs/rockchip-io-domain.c      |   24 ++++++++++++------------
 drivers/power/reset/at91-sama5d2_shdwc.c    |    4 ++--
 drivers/power/supply/axp20x_ac_power.c      |    8 ++++----
 drivers/spi/spi-fsl-dspi.c                  |    7 +++----
 drivers/spi/spi-sirf.c                      |    4 ++--
 13 files changed, 44 insertions(+), 44 deletions(-)

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

* [PATCH 02/12] pinctrl: at91-pio4: account for const type of of_device_id.data
  2018-01-02 13:27 [PATCH 00/12] account for const type of of_device_id.data Julia Lawall
@ 2018-01-02 13:27 ` Julia Lawall
  2018-01-03  7:58   ` Linus Walleij
  2018-01-02 13:28 ` [PATCH 05/12] pinctrl: armada-37xx: " Julia Lawall
  2018-01-02 13:28 ` [PATCH 08/12] pinctrl: axp209: " Julia Lawall
  2 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2018-01-02 13:27 UTC (permalink / raw)
  To: Ludovic Desroches
  Cc: Linus Walleij, kernel-janitors, linux-kernel, linux-gpio,
	Alexandre Belloni, linux-arm-kernel

This driver creates a const structure that it stores in the data field
of an of_device_id array.

Adding const to the declaration of the location that receives the
const value from the data field ensures that the compiler will
continue to check that the value is not modified.  Furthermore, the
const-discarding cast on the extraction from the data field is no
longer needed.

Done using Coccinelle.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/pinctrl/pinctrl-at91-pio4.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -u -p a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c
--- a/drivers/pinctrl/pinctrl-at91-pio4.c
+++ b/drivers/pinctrl/pinctrl-at91-pio4.c
@@ -910,7 +910,7 @@ static int atmel_pinctrl_probe(struct pl
 	int i, ret;
 	struct resource	*res;
 	struct atmel_pioctrl *atmel_pioctrl;
-	struct atmel_pioctrl_data *atmel_pioctrl_data;
+	const struct atmel_pioctrl_data *atmel_pioctrl_data;
 
 	atmel_pioctrl = devm_kzalloc(dev, sizeof(*atmel_pioctrl), GFP_KERNEL);
 	if (!atmel_pioctrl)
@@ -924,7 +924,7 @@ static int atmel_pinctrl_probe(struct pl
 		dev_err(dev, "unknown compatible string\n");
 		return -ENODEV;
 	}
-	atmel_pioctrl_data = (struct atmel_pioctrl_data *)match->data;
+	atmel_pioctrl_data = match->data;
 	atmel_pioctrl->nbanks = atmel_pioctrl_data->nbanks;
 	atmel_pioctrl->npins = atmel_pioctrl->nbanks * ATMEL_PIO_NPINS_PER_BANK;

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

* [PATCH 05/12] pinctrl: armada-37xx: account for const type of of_device_id.data
  2018-01-02 13:27 [PATCH 00/12] account for const type of of_device_id.data Julia Lawall
  2018-01-02 13:27 ` [PATCH 02/12] pinctrl: at91-pio4: " Julia Lawall
@ 2018-01-02 13:28 ` Julia Lawall
  2018-01-02 15:36   ` Gregory CLEMENT
  2018-01-03  8:03   ` Linus Walleij
  2018-01-02 13:28 ` [PATCH 08/12] pinctrl: axp209: " Julia Lawall
  2 siblings, 2 replies; 8+ messages in thread
From: Julia Lawall @ 2018-01-02 13:28 UTC (permalink / raw)
  To: Jason Cooper
  Cc: kernel-janitors, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, Linus Walleij, linux-arm-kernel,
	linux-gpio, linux-kernel

The data field of an of_device_id structure has type const void *, so
there is no need for a const-discarding cast when putting const values
into such a structure.

Done using Coccinelle.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -u -p a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -1006,11 +1006,11 @@ static int armada_37xx_pinctrl_register(
 static const struct of_device_id armada_37xx_pinctrl_of_match[] = {
 	{
 		.compatible = "marvell,armada3710-sb-pinctrl",
-		.data = (void *)&armada_37xx_pin_sb,
+		.data = &armada_37xx_pin_sb,
 	},
 	{
 		.compatible = "marvell,armada3710-nb-pinctrl",
-		.data = (void *)&armada_37xx_pin_nb,
+		.data = &armada_37xx_pin_nb,
 	},
 	{ },
 };

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

* [PATCH 08/12] pinctrl: axp209: account for const type of of_device_id.data
  2018-01-02 13:27 [PATCH 00/12] account for const type of of_device_id.data Julia Lawall
  2018-01-02 13:27 ` [PATCH 02/12] pinctrl: at91-pio4: " Julia Lawall
  2018-01-02 13:28 ` [PATCH 05/12] pinctrl: armada-37xx: " Julia Lawall
@ 2018-01-02 13:28 ` Julia Lawall
  2018-01-03  7:59   ` Linus Walleij
  2 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2018-01-02 13:28 UTC (permalink / raw)
  To: Linus Walleij; +Cc: kernel-janitors, Chen-Yu Tsai, linux-gpio, linux-kernel

The return value of of_device_get_match_data has type const void *.
The desc field of the pctl structure also has a const type, so there
is no need for the const-discarding cast between them.

Done using Coccinelle.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/pinctrl/pinctrl-axp209.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c
--- a/drivers/pinctrl/pinctrl-axp209.c
+++ b/drivers/pinctrl/pinctrl-axp209.c
@@ -414,7 +414,7 @@ static int axp20x_pctl_probe(struct plat
 	pctl->chip.direction_input	= axp20x_gpio_input;
 	pctl->chip.direction_output	= axp20x_gpio_output;
 
-	pctl->desc = (struct axp20x_pctrl_desc *)of_device_get_match_data(dev);
+	pctl->desc = of_device_get_match_data(dev);
 
 	pctl->chip.ngpio		= pctl->desc->npins;
 

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

* Re: [PATCH 05/12] pinctrl: armada-37xx: account for const type of of_device_id.data
  2018-01-02 13:28 ` [PATCH 05/12] pinctrl: armada-37xx: " Julia Lawall
@ 2018-01-02 15:36   ` Gregory CLEMENT
  2018-01-03  8:03   ` Linus Walleij
  1 sibling, 0 replies; 8+ messages in thread
From: Gregory CLEMENT @ 2018-01-02 15:36 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Jason Cooper, Andrew Lunn, Linus Walleij, kernel-janitors,
	linux-kernel, linux-gpio, linux-arm-kernel, Sebastian Hesselbarth

Hi Julia,
 
 On mar., janv. 02 2018, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> The data field of an of_device_id structure has type const void *, so
> there is no need for a const-discarding cast when putting const values
> into such a structure.
>
> Done using Coccinelle.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>


Acked-by: Gregory CLEMENT <gregory.clement@free-electrons.com>

Thanks,

Gregory


PS: actually the intent was not to do a const-discarding cast it was
just a useless cast! :)


>
> ---
>  drivers/pinctrl/mvebu/pinctrl-armada-37xx.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff -u -p a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
> --- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
> +++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
> @@ -1006,11 +1006,11 @@ static int armada_37xx_pinctrl_register(
>  static const struct of_device_id armada_37xx_pinctrl_of_match[] = {
>  	{
>  		.compatible = "marvell,armada3710-sb-pinctrl",
> -		.data = (void *)&armada_37xx_pin_sb,
> +		.data = &armada_37xx_pin_sb,
>  	},
>  	{
>  		.compatible = "marvell,armada3710-nb-pinctrl",
> -		.data = (void *)&armada_37xx_pin_nb,
> +		.data = &armada_37xx_pin_nb,
>  	},
>  	{ },
>  };
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

-- 
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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

* Re: [PATCH 02/12] pinctrl: at91-pio4: account for const type of of_device_id.data
  2018-01-02 13:27 ` [PATCH 02/12] pinctrl: at91-pio4: " Julia Lawall
@ 2018-01-03  7:58   ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2018-01-03  7:58 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Ludovic Desroches, kernel-janitors, Nicolas Ferre,
	Alexandre Belloni, Linux ARM, linux-gpio,
	linux-kernel@vger.kernel.org

On Tue, Jan 2, 2018 at 2:27 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> This driver creates a const structure that it stores in the data field
> of an of_device_id array.
>
> Adding const to the declaration of the location that receives the
> const value from the data field ensures that the compiler will
> continue to check that the value is not modified.  Furthermore, the
> const-discarding cast on the extraction from the data field is no
> longer needed.
>
> Done using Coccinelle.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH 08/12] pinctrl: axp209: account for const type of of_device_id.data
  2018-01-02 13:28 ` [PATCH 08/12] pinctrl: axp209: " Julia Lawall
@ 2018-01-03  7:59   ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2018-01-03  7:59 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Chen-Yu Tsai, linux-gpio,
	linux-kernel@vger.kernel.org

On Tue, Jan 2, 2018 at 2:28 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> The return value of of_device_get_match_data has type const void *.
> The desc field of the pctl structure also has a const type, so there
> is no need for the const-discarding cast between them.
>
> Done using Coccinelle.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH 05/12] pinctrl: armada-37xx: account for const type of of_device_id.data
  2018-01-02 13:28 ` [PATCH 05/12] pinctrl: armada-37xx: " Julia Lawall
  2018-01-02 15:36   ` Gregory CLEMENT
@ 2018-01-03  8:03   ` Linus Walleij
  1 sibling, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2018-01-03  8:03 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Jason Cooper, kernel-janitors, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, Linux ARM, linux-gpio,
	linux-kernel@vger.kernel.org

On Tue, Jan 2, 2018 at 2:28 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> The data field of an of_device_id structure has type const void *, so
> there is no need for a const-discarding cast when putting const values
> into such a structure.
>
> Done using Coccinelle.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Patch applied with Gregory's ACK.

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-01-03  8:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-02 13:27 [PATCH 00/12] account for const type of of_device_id.data Julia Lawall
2018-01-02 13:27 ` [PATCH 02/12] pinctrl: at91-pio4: " Julia Lawall
2018-01-03  7:58   ` Linus Walleij
2018-01-02 13:28 ` [PATCH 05/12] pinctrl: armada-37xx: " Julia Lawall
2018-01-02 15:36   ` Gregory CLEMENT
2018-01-03  8:03   ` Linus Walleij
2018-01-02 13:28 ` [PATCH 08/12] pinctrl: axp209: " Julia Lawall
2018-01-03  7:59   ` 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).