Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH 0/3] w1: Constify w1_family_ops
@ 2020-10-04 19:31 Rikard Falkeborn
  2020-10-04 19:32 ` [PATCH 3/3] power: supply: Constify static w1_family_ops structs Rikard Falkeborn
  0 siblings, 1 reply; 3+ messages in thread
From: Rikard Falkeborn @ 2020-10-04 19:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, Rikard Falkeborn, Sebastian Reichel,
	Angelo Dureghello, Akira Shimahara, Evgeniy Polyakov, linux-pm

None of the current instances of struct w1_family_ops in the kernel is
modified. Constify these to let the compiler put them in read-only memory.

The first patch changes the fops field in w1_family struct to a pointer to
const and makes a local variable a pointer to const to avoid a compiler
warning. This patch is a prerequisite for the second and third patches
which constifies the static structs in drivers in w1 and power. These
changes was done with coccinelle (details in the commit messages).

With these changes applied, all instances of struct w1_family_ops in the
kernel are const.

Build-tested on x86 allmodconfig.

Rikard Falkeborn (3):
  w1: Constify struct w1_family_ops
  w1: Constify static w1_family_ops structs
  power: supply: Constify static w1_family_ops structs

 drivers/power/supply/bq27xxx_battery_hdq.c | 2 +-
 drivers/power/supply/ds2760_battery.c      | 2 +-
 drivers/power/supply/max1721x_battery.c    | 2 +-
 drivers/w1/slaves/w1_ds2405.c              | 2 +-
 drivers/w1/slaves/w1_ds2406.c              | 2 +-
 drivers/w1/slaves/w1_ds2408.c              | 2 +-
 drivers/w1/slaves/w1_ds2413.c              | 2 +-
 drivers/w1/slaves/w1_ds2423.c              | 2 +-
 drivers/w1/slaves/w1_ds2430.c              | 2 +-
 drivers/w1/slaves/w1_ds2431.c              | 2 +-
 drivers/w1/slaves/w1_ds2433.c              | 2 +-
 drivers/w1/slaves/w1_ds2438.c              | 2 +-
 drivers/w1/slaves/w1_ds250x.c              | 2 +-
 drivers/w1/slaves/w1_ds2780.c              | 2 +-
 drivers/w1/slaves/w1_ds2781.c              | 2 +-
 drivers/w1/slaves/w1_ds2805.c              | 2 +-
 drivers/w1/slaves/w1_ds28e04.c             | 2 +-
 drivers/w1/slaves/w1_ds28e17.c             | 2 +-
 drivers/w1/slaves/w1_therm.c               | 6 +++---
 drivers/w1/w1.c                            | 4 ++--
 include/linux/w1.h                         | 2 +-
 21 files changed, 24 insertions(+), 24 deletions(-)

-- 
2.28.0


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

* [PATCH 3/3] power: supply: Constify static w1_family_ops structs
  2020-10-04 19:31 [PATCH 0/3] w1: Constify w1_family_ops Rikard Falkeborn
@ 2020-10-04 19:32 ` Rikard Falkeborn
  2020-10-04 22:03   ` Sebastian Reichel
  0 siblings, 1 reply; 3+ messages in thread
From: Rikard Falkeborn @ 2020-10-04 19:32 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, Rikard Falkeborn, Sebastian Reichel, linux-pm

The only usage of these structs is to assign their address to the fops
field in the w1_family struct, which is a const pointer. Make them const
to allow the compiler to put them in read-only memory.

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

// <smpl>
@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct w1_family_ops i@p = {...};

@ok1@
identifier r1.i;
position p;
identifier s;
@@
static struct w1_family s = {
	.fops=&i@p,
};

@bad1@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad1 disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct w1_family_ops i={};
// </smpl>

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
---
 drivers/power/supply/bq27xxx_battery_hdq.c | 2 +-
 drivers/power/supply/ds2760_battery.c      | 2 +-
 drivers/power/supply/max1721x_battery.c    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/bq27xxx_battery_hdq.c b/drivers/power/supply/bq27xxx_battery_hdq.c
index 12b10dad77d3..922759ab2e04 100644
--- a/drivers/power/supply/bq27xxx_battery_hdq.c
+++ b/drivers/power/supply/bq27xxx_battery_hdq.c
@@ -97,7 +97,7 @@ static void bq27xxx_battery_hdq_remove_slave(struct w1_slave *sl)
 	bq27xxx_battery_teardown(di);
 }
 
-static struct w1_family_ops bq27xxx_battery_hdq_fops = {
+static const struct w1_family_ops bq27xxx_battery_hdq_fops = {
 	.add_slave	= bq27xxx_battery_hdq_add_slave,
 	.remove_slave	= bq27xxx_battery_hdq_remove_slave,
 };
diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c
index 11bed88a89fa..695bb6747400 100644
--- a/drivers/power/supply/ds2760_battery.c
+++ b/drivers/power/supply/ds2760_battery.c
@@ -795,7 +795,7 @@ static const struct of_device_id w1_ds2760_of_ids[] = {
 };
 #endif
 
-static struct w1_family_ops w1_ds2760_fops = {
+static const struct w1_family_ops w1_ds2760_fops = {
 	.add_slave	= w1_ds2760_add_slave,
 	.remove_slave	= w1_ds2760_remove_slave,
 	.groups		= w1_ds2760_groups,
diff --git a/drivers/power/supply/max1721x_battery.c b/drivers/power/supply/max1721x_battery.c
index 9ca895b0dabb..1b1a36f8e929 100644
--- a/drivers/power/supply/max1721x_battery.c
+++ b/drivers/power/supply/max1721x_battery.c
@@ -431,7 +431,7 @@ static int devm_w1_max1721x_add_device(struct w1_slave *sl)
 	return 0;
 }
 
-static struct w1_family_ops w1_max1721x_fops = {
+static const struct w1_family_ops w1_max1721x_fops = {
 	.add_slave = devm_w1_max1721x_add_device,
 };
 
-- 
2.28.0


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

* Re: [PATCH 3/3] power: supply: Constify static w1_family_ops structs
  2020-10-04 19:32 ` [PATCH 3/3] power: supply: Constify static w1_family_ops structs Rikard Falkeborn
@ 2020-10-04 22:03   ` Sebastian Reichel
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2020-10-04 22:03 UTC (permalink / raw)
  To: Rikard Falkeborn; +Cc: Greg Kroah-Hartman, linux-kernel, linux-pm

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

Hi,

On Sun, Oct 04, 2020 at 09:32:02PM +0200, Rikard Falkeborn wrote:
> The only usage of these structs is to assign their address to the fops
> field in the w1_family struct, which is a const pointer. Make them const
> to allow the compiler to put them in read-only memory.
> 
> This was done with the following Coccinelle semantic patch
> (http://coccinelle.lip6.fr/):
> 
> // <smpl>
> @r1 disable optional_qualifier @
> identifier i;
> position p;
> @@
> static struct w1_family_ops i@p = {...};
> 
> @ok1@
> identifier r1.i;
> position p;
> identifier s;
> @@
> static struct w1_family s = {
> 	.fops=&i@p,
> };
> 
> @bad1@
> position p!={r1.p,ok1.p};
> identifier r1.i;
> @@
> i@p
> 
> @depends on !bad1 disable optional_qualifier@
> identifier r1.i;
> @@
> static
> +const
> struct w1_family_ops i={};
> // </smpl>
> 
> Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
> ---

I suggest that this simply goes through the w1 tree together
with the other patches:

Acked-by: Sebastian Reichel <sre@kernel.org>

-- Sebastian

>  drivers/power/supply/bq27xxx_battery_hdq.c | 2 +-
>  drivers/power/supply/ds2760_battery.c      | 2 +-
>  drivers/power/supply/max1721x_battery.c    | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/supply/bq27xxx_battery_hdq.c b/drivers/power/supply/bq27xxx_battery_hdq.c
> index 12b10dad77d3..922759ab2e04 100644
> --- a/drivers/power/supply/bq27xxx_battery_hdq.c
> +++ b/drivers/power/supply/bq27xxx_battery_hdq.c
> @@ -97,7 +97,7 @@ static void bq27xxx_battery_hdq_remove_slave(struct w1_slave *sl)
>  	bq27xxx_battery_teardown(di);
>  }
>  
> -static struct w1_family_ops bq27xxx_battery_hdq_fops = {
> +static const struct w1_family_ops bq27xxx_battery_hdq_fops = {
>  	.add_slave	= bq27xxx_battery_hdq_add_slave,
>  	.remove_slave	= bq27xxx_battery_hdq_remove_slave,
>  };
> diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c
> index 11bed88a89fa..695bb6747400 100644
> --- a/drivers/power/supply/ds2760_battery.c
> +++ b/drivers/power/supply/ds2760_battery.c
> @@ -795,7 +795,7 @@ static const struct of_device_id w1_ds2760_of_ids[] = {
>  };
>  #endif
>  
> -static struct w1_family_ops w1_ds2760_fops = {
> +static const struct w1_family_ops w1_ds2760_fops = {
>  	.add_slave	= w1_ds2760_add_slave,
>  	.remove_slave	= w1_ds2760_remove_slave,
>  	.groups		= w1_ds2760_groups,
> diff --git a/drivers/power/supply/max1721x_battery.c b/drivers/power/supply/max1721x_battery.c
> index 9ca895b0dabb..1b1a36f8e929 100644
> --- a/drivers/power/supply/max1721x_battery.c
> +++ b/drivers/power/supply/max1721x_battery.c
> @@ -431,7 +431,7 @@ static int devm_w1_max1721x_add_device(struct w1_slave *sl)
>  	return 0;
>  }
>  
> -static struct w1_family_ops w1_max1721x_fops = {
> +static const struct w1_family_ops w1_max1721x_fops = {
>  	.add_slave = devm_w1_max1721x_add_device,
>  };
>  
> -- 
> 2.28.0
> 

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

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

end of thread, other threads:[~2020-10-04 22:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-04 19:31 [PATCH 0/3] w1: Constify w1_family_ops Rikard Falkeborn
2020-10-04 19:32 ` [PATCH 3/3] power: supply: Constify static w1_family_ops structs Rikard Falkeborn
2020-10-04 22:03   ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox