linux-pm.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 01/12] PM / AVS: rockchip-io: " Julia Lawall
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ 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] 7+ messages in thread

* [PATCH 01/12] PM / AVS: rockchip-io: 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-02 13:28 ` [PATCH 06/12] power: supply: " Julia Lawall
  2018-01-02 13:28 ` [PATCH 12/12] power: reset: " Julia Lawall
  2 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2018-01-02 13:27 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Nishanth Menon, Heiko Stuebner, linux-pm, kernel-janitors,
	linux-kernel, linux-rockchip, linux-arm-kernel

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

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.

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

Done using Coccinelle.

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

---
 drivers/power/avs/rockchip-io-domain.c |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff -u -p a/drivers/power/avs/rockchip-io-domain.c b/drivers/power/avs/rockchip-io-domain.c
--- a/drivers/power/avs/rockchip-io-domain.c
+++ b/drivers/power/avs/rockchip-io-domain.c
@@ -76,7 +76,7 @@ struct rockchip_iodomain_supply {
 struct rockchip_iodomain {
 	struct device *dev;
 	struct regmap *grf;
-	struct rockchip_iodomain_soc_data *soc_data;
+	const struct rockchip_iodomain_soc_data *soc_data;
 	struct rockchip_iodomain_supply supplies[MAX_SUPPLIES];
 };
 
@@ -382,43 +382,43 @@ static const struct rockchip_iodomain_so
 static const struct of_device_id rockchip_iodomain_match[] = {
 	{
 		.compatible = "rockchip,rk3188-io-voltage-domain",
-		.data = (void *)&soc_data_rk3188
+		.data = &soc_data_rk3188
 	},
 	{
 		.compatible = "rockchip,rk3228-io-voltage-domain",
-		.data = (void *)&soc_data_rk3228
+		.data = &soc_data_rk3228
 	},
 	{
 		.compatible = "rockchip,rk3288-io-voltage-domain",
-		.data = (void *)&soc_data_rk3288
+		.data = &soc_data_rk3288
 	},
 	{
 		.compatible = "rockchip,rk3328-io-voltage-domain",
-		.data = (void *)&soc_data_rk3328
+		.data = &soc_data_rk3328
 	},
 	{
 		.compatible = "rockchip,rk3368-io-voltage-domain",
-		.data = (void *)&soc_data_rk3368
+		.data = &soc_data_rk3368
 	},
 	{
 		.compatible = "rockchip,rk3368-pmu-io-voltage-domain",
-		.data = (void *)&soc_data_rk3368_pmu
+		.data = &soc_data_rk3368_pmu
 	},
 	{
 		.compatible = "rockchip,rk3399-io-voltage-domain",
-		.data = (void *)&soc_data_rk3399
+		.data = &soc_data_rk3399
 	},
 	{
 		.compatible = "rockchip,rk3399-pmu-io-voltage-domain",
-		.data = (void *)&soc_data_rk3399_pmu
+		.data = &soc_data_rk3399_pmu
 	},
 	{
 		.compatible = "rockchip,rv1108-io-voltage-domain",
-		.data = (void *)&soc_data_rv1108
+		.data = &soc_data_rv1108
 	},
 	{
 		.compatible = "rockchip,rv1108-pmu-io-voltage-domain",
-		.data = (void *)&soc_data_rv1108_pmu
+		.data = &soc_data_rv1108_pmu
 	},
 	{ /* sentinel */ },
 };
@@ -443,7 +443,7 @@ static int rockchip_iodomain_probe(struc
 	platform_set_drvdata(pdev, iod);
 
 	match = of_match_node(rockchip_iodomain_match, np);
-	iod->soc_data = (struct rockchip_iodomain_soc_data *)match->data;
+	iod->soc_data = match->data;
 
 	parent = pdev->dev.parent;
 	if (parent && parent->of_node) {

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

* [PATCH 06/12] power: supply: 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 01/12] PM / AVS: rockchip-io: " Julia Lawall
@ 2018-01-02 13:28 ` Julia Lawall
  2018-01-09 16:22   ` Sebastian Reichel
  2018-01-02 13:28 ` [PATCH 12/12] power: reset: " Julia Lawall
  2 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2018-01-02 13:28 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: kernel-janitors, Chen-Yu Tsai, linux-pm, linux-kernel

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

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.

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

Done using Coccinelle.

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

---
 drivers/power/supply/axp20x_ac_power.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff -u -p a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c
--- a/drivers/power/supply/axp20x_ac_power.c
+++ b/drivers/power/supply/axp20x_ac_power.c
@@ -159,7 +159,7 @@ static int axp20x_ac_power_probe(struct
 	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
 	struct power_supply_config psy_cfg = {};
 	struct axp20x_ac_power *power;
-	struct axp_data *axp_data;
+	const struct axp_data *axp_data;
 	static const char * const irq_names[] = { "ACIN_PLUGIN", "ACIN_REMOVAL",
 		NULL };
 	int i, irq, ret;
@@ -176,7 +176,7 @@ static int axp20x_ac_power_probe(struct
 	if (!power)
 		return -ENOMEM;
 
-	axp_data = (struct axp_data *)of_device_get_match_data(&pdev->dev);
+	axp_data = of_device_get_match_data(&pdev->dev);
 
 	if (axp_data->acin_adc) {
 		power->acin_v = devm_iio_channel_get(&pdev->dev, "acin_v");
@@ -230,10 +230,10 @@ static int axp20x_ac_power_probe(struct
 static const struct of_device_id axp20x_ac_power_match[] = {
 	{
 		.compatible = "x-powers,axp202-ac-power-supply",
-		.data = (void *)&axp20x_data,
+		.data = &axp20x_data,
 	}, {
 		.compatible = "x-powers,axp221-ac-power-supply",
-		.data = (void *)&axp22x_data,
+		.data = &axp22x_data,
 	}, { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, axp20x_ac_power_match);


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

* [PATCH 12/12] power: reset: 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 01/12] PM / AVS: rockchip-io: " Julia Lawall
  2018-01-02 13:28 ` [PATCH 06/12] power: supply: " Julia Lawall
@ 2018-01-02 13:28 ` Julia Lawall
  2018-01-05 13:24   ` Alexandre Belloni
  2018-01-09 16:22   ` Sebastian Reichel
  2 siblings, 2 replies; 7+ messages in thread
From: Julia Lawall @ 2018-01-02 13:28 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: kernel-janitors, Sebastian Reichel, Alexandre Belloni, linux-pm,
	linux-arm-kernel, linux-kernel

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

Add const to the declaration of the location that receives a value
from the data field to ensure that the compiler will continue to check
that the value is not modified and remove the const-dropping cast on
the access to the data field.

Done using Coccinelle.

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

---
 drivers/power/reset/at91-sama5d2_shdwc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -u -p a/drivers/power/reset/at91-sama5d2_shdwc.c b/drivers/power/reset/at91-sama5d2_shdwc.c
--- a/drivers/power/reset/at91-sama5d2_shdwc.c
+++ b/drivers/power/reset/at91-sama5d2_shdwc.c
@@ -68,7 +68,7 @@ struct shdwc_config {
 };
 
 struct shdwc {
-	struct shdwc_config *cfg;
+	const struct shdwc_config *cfg;
 	void __iomem *at91_shdwc_base;
 };
 
@@ -260,7 +260,7 @@ static int __init at91_shdwc_probe(struc
 	}
 
 	match = of_match_node(at91_shdwc_of_match, pdev->dev.of_node);
-	at91_shdwc->cfg = (struct shdwc_config *)(match->data);
+	at91_shdwc->cfg = match->data;
 
 	sclk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(sclk))

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

* Re: [PATCH 12/12] power: reset: account for const type of of_device_id.data
  2018-01-02 13:28 ` [PATCH 12/12] power: reset: " Julia Lawall
@ 2018-01-05 13:24   ` Alexandre Belloni
  2018-01-09 16:22   ` Sebastian Reichel
  1 sibling, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2018-01-05 13:24 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Nicolas Ferre, kernel-janitors, Sebastian Reichel, linux-pm,
	linux-arm-kernel, linux-kernel

On 02/01/2018 at 14:28:08 +0100, Julia Lawall wrote:
> This driver creates a const structure that it stores in the data
> field of an of_device_id array.
> 
> Add const to the declaration of the location that receives a value
> from the data field to ensure that the compiler will continue to check
> that the value is not modified and remove the const-dropping cast on
> the access to the data field.
> 
> Done using Coccinelle.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH 06/12] power: supply: account for const type of of_device_id.data
  2018-01-02 13:28 ` [PATCH 06/12] power: supply: " Julia Lawall
@ 2018-01-09 16:22   ` Sebastian Reichel
  0 siblings, 0 replies; 7+ messages in thread
From: Sebastian Reichel @ 2018-01-09 16:22 UTC (permalink / raw)
  To: Julia Lawall; +Cc: kernel-janitors, Chen-Yu Tsai, linux-pm, linux-kernel

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

Hi,

On Tue, Jan 02, 2018 at 02:28:02PM +0100, Julia Lawall wrote:
> This driver creates two const structures that it stores in the data
> field of an of_device_id array.
> 
> 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.
> 
> Furthermore, adding const to the declaration of the location that
> receives a const value from such a field ensures that the compiler
> will continue to check that the value is not modified.  The
> const-discarding cast on the extraction from the data field is thus
> no longer needed.
> 
> Done using Coccinelle.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/axp20x_ac_power.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff -u -p a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c
> --- a/drivers/power/supply/axp20x_ac_power.c
> +++ b/drivers/power/supply/axp20x_ac_power.c
> @@ -159,7 +159,7 @@ static int axp20x_ac_power_probe(struct
>  	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
>  	struct power_supply_config psy_cfg = {};
>  	struct axp20x_ac_power *power;
> -	struct axp_data *axp_data;
> +	const struct axp_data *axp_data;
>  	static const char * const irq_names[] = { "ACIN_PLUGIN", "ACIN_REMOVAL",
>  		NULL };
>  	int i, irq, ret;
> @@ -176,7 +176,7 @@ static int axp20x_ac_power_probe(struct
>  	if (!power)
>  		return -ENOMEM;
>  
> -	axp_data = (struct axp_data *)of_device_get_match_data(&pdev->dev);
> +	axp_data = of_device_get_match_data(&pdev->dev);
>  
>  	if (axp_data->acin_adc) {
>  		power->acin_v = devm_iio_channel_get(&pdev->dev, "acin_v");
> @@ -230,10 +230,10 @@ static int axp20x_ac_power_probe(struct
>  static const struct of_device_id axp20x_ac_power_match[] = {
>  	{
>  		.compatible = "x-powers,axp202-ac-power-supply",
> -		.data = (void *)&axp20x_data,
> +		.data = &axp20x_data,
>  	}, {
>  		.compatible = "x-powers,axp221-ac-power-supply",
> -		.data = (void *)&axp22x_data,
> +		.data = &axp22x_data,
>  	}, { /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, axp20x_ac_power_match);
> 

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

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

* Re: [PATCH 12/12] power: reset: account for const type of of_device_id.data
  2018-01-02 13:28 ` [PATCH 12/12] power: reset: " Julia Lawall
  2018-01-05 13:24   ` Alexandre Belloni
@ 2018-01-09 16:22   ` Sebastian Reichel
  1 sibling, 0 replies; 7+ messages in thread
From: Sebastian Reichel @ 2018-01-09 16:22 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Nicolas Ferre, kernel-janitors, Alexandre Belloni, linux-pm,
	linux-arm-kernel, linux-kernel

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

Hi,

On Tue, Jan 02, 2018 at 02:28:08PM +0100, Julia Lawall wrote:
> This driver creates a const structure that it stores in the data
> field of an of_device_id array.
> 
> Add const to the declaration of the location that receives a value
> from the data field to ensure that the compiler will continue to check
> that the value is not modified and remove the const-dropping cast on
> the access to the data field.
> 
> Done using Coccinelle.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/reset/at91-sama5d2_shdwc.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff -u -p a/drivers/power/reset/at91-sama5d2_shdwc.c b/drivers/power/reset/at91-sama5d2_shdwc.c
> --- a/drivers/power/reset/at91-sama5d2_shdwc.c
> +++ b/drivers/power/reset/at91-sama5d2_shdwc.c
> @@ -68,7 +68,7 @@ struct shdwc_config {
>  };
>  
>  struct shdwc {
> -	struct shdwc_config *cfg;
> +	const struct shdwc_config *cfg;
>  	void __iomem *at91_shdwc_base;
>  };
>  
> @@ -260,7 +260,7 @@ static int __init at91_shdwc_probe(struc
>  	}
>  
>  	match = of_match_node(at91_shdwc_of_match, pdev->dev.of_node);
> -	at91_shdwc->cfg = (struct shdwc_config *)(match->data);
> +	at91_shdwc->cfg = match->data;
>  
>  	sclk = devm_clk_get(&pdev->dev, NULL);
>  	if (IS_ERR(sclk))
> 

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

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

end of thread, other threads:[~2018-01-09 16:22 UTC | newest]

Thread overview: 7+ 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 01/12] PM / AVS: rockchip-io: " Julia Lawall
2018-01-02 13:28 ` [PATCH 06/12] power: supply: " Julia Lawall
2018-01-09 16:22   ` Sebastian Reichel
2018-01-02 13:28 ` [PATCH 12/12] power: reset: " Julia Lawall
2018-01-05 13:24   ` Alexandre Belloni
2018-01-09 16:22   ` Sebastian Reichel

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