Skip to content

Commit

Permalink
power: supply: Constify static w1_family_ops structs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Rikard Falkeborn <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
rikardfalkeborn authored and gregkh committed Oct 5, 2020
1 parent 57de2df commit 6925478
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/power/supply/bq27xxx_battery_hdq.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/supply/ds2760_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/supply/max1721x_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit 6925478

Please sign in to comment.