Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: Constify static w1_family_ops structs

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>

Acked-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Link: https://lore.kernel.org/r/20201004193202.4044-4-rikard.falkeborn@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rikard Falkeborn and committed by
Greg Kroah-Hartman
6925478c 57de2dfc

+3 -3
+1 -1
drivers/power/supply/bq27xxx_battery_hdq.c
··· 104 104 bq27xxx_battery_teardown(di); 105 105 } 106 106 107 - static struct w1_family_ops bq27xxx_battery_hdq_fops = { 107 + static const struct w1_family_ops bq27xxx_battery_hdq_fops = { 108 108 .add_slave = bq27xxx_battery_hdq_add_slave, 109 109 .remove_slave = bq27xxx_battery_hdq_remove_slave, 110 110 };
+1 -1
drivers/power/supply/ds2760_battery.c
··· 795 795 }; 796 796 #endif 797 797 798 - static struct w1_family_ops w1_ds2760_fops = { 798 + static const struct w1_family_ops w1_ds2760_fops = { 799 799 .add_slave = w1_ds2760_add_slave, 800 800 .remove_slave = w1_ds2760_remove_slave, 801 801 .groups = w1_ds2760_groups,
+1 -1
drivers/power/supply/max1721x_battery.c
··· 431 431 return 0; 432 432 } 433 433 434 - static struct w1_family_ops w1_max1721x_fops = { 434 + static const struct w1_family_ops w1_max1721x_fops = { 435 435 .add_slave = devm_w1_max1721x_add_device, 436 436 }; 437 437