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

w1: 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>

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

authored by

Rikard Falkeborn and committed by
Greg Kroah-Hartman
57de2dfc 07f8569f

+19 -19
+1 -1
drivers/w1/slaves/w1_ds2405.c
··· 206 206 207 207 ATTRIBUTE_GROUPS(w1_ds2405); 208 208 209 - static struct w1_family_ops w1_ds2405_fops = { 209 + static const struct w1_family_ops w1_ds2405_fops = { 210 210 .groups = w1_ds2405_groups 211 211 }; 212 212
+1 -1
drivers/w1/slaves/w1_ds2406.c
··· 138 138 &(w1_f12_sysfs_bin_files[i])); 139 139 } 140 140 141 - static struct w1_family_ops w1_f12_fops = { 141 + static const struct w1_family_ops w1_f12_fops = { 142 142 .add_slave = w1_f12_add_slave, 143 143 .remove_slave = w1_f12_remove_slave, 144 144 };
+1 -1
drivers/w1/slaves/w1_ds2408.c
··· 336 336 NULL, 337 337 }; 338 338 339 - static struct w1_family_ops w1_f29_fops = { 339 + static const struct w1_family_ops w1_f29_fops = { 340 340 .add_slave = w1_f29_disable_test_mode, 341 341 .groups = w1_f29_groups, 342 342 };
+1 -1
drivers/w1/slaves/w1_ds2413.c
··· 143 143 NULL, 144 144 }; 145 145 146 - static struct w1_family_ops w1_f3a_fops = { 146 + static const struct w1_family_ops w1_f3a_fops = { 147 147 .groups = w1_f3a_groups, 148 148 }; 149 149
+1 -1
drivers/w1/slaves/w1_ds2423.c
··· 117 117 }; 118 118 ATTRIBUTE_GROUPS(w1_f1d); 119 119 120 - static struct w1_family_ops w1_f1d_fops = { 120 + static const struct w1_family_ops w1_f1d_fops = { 121 121 .groups = w1_f1d_groups, 122 122 }; 123 123
+1 -1
drivers/w1/slaves/w1_ds2430.c
··· 279 279 NULL, 280 280 }; 281 281 282 - static struct w1_family_ops w1_f14_fops = { 282 + static const struct w1_family_ops w1_f14_fops = { 283 283 .groups = w1_f14_groups, 284 284 }; 285 285
+1 -1
drivers/w1/slaves/w1_ds2431.c
··· 278 278 NULL, 279 279 }; 280 280 281 - static struct w1_family_ops w1_f2d_fops = { 281 + static const struct w1_family_ops w1_f2d_fops = { 282 282 .groups = w1_f2d_groups, 283 283 }; 284 284
+1 -1
drivers/w1/slaves/w1_ds2433.c
··· 288 288 #endif /* CONFIG_W1_SLAVE_DS2433_CRC */ 289 289 } 290 290 291 - static struct w1_family_ops w1_f23_fops = { 291 + static const struct w1_family_ops w1_f23_fops = { 292 292 .add_slave = w1_f23_add_slave, 293 293 .remove_slave = w1_f23_remove_slave, 294 294 .groups = w1_f23_groups,
+1 -1
drivers/w1/slaves/w1_ds2438.c
··· 412 412 NULL, 413 413 }; 414 414 415 - static struct w1_family_ops w1_ds2438_fops = { 415 + static const struct w1_family_ops w1_ds2438_fops = { 416 416 .groups = w1_ds2438_groups, 417 417 }; 418 418
+1 -1
drivers/w1/slaves/w1_ds250x.c
··· 215 215 return PTR_ERR_OR_ZERO(nvmem); 216 216 } 217 217 218 - static struct w1_family_ops w1_eprom_fops = { 218 + static const struct w1_family_ops w1_eprom_fops = { 219 219 .add_slave = w1_eprom_add_slave, 220 220 }; 221 221
+1 -1
drivers/w1/slaves/w1_ds2780.c
··· 141 141 platform_device_unregister(pdev); 142 142 } 143 143 144 - static struct w1_family_ops w1_ds2780_fops = { 144 + static const struct w1_family_ops w1_ds2780_fops = { 145 145 .add_slave = w1_ds2780_add_slave, 146 146 .remove_slave = w1_ds2780_remove_slave, 147 147 .groups = w1_ds2780_groups,
+1 -1
drivers/w1/slaves/w1_ds2781.c
··· 138 138 platform_device_unregister(pdev); 139 139 } 140 140 141 - static struct w1_family_ops w1_ds2781_fops = { 141 + static const struct w1_family_ops w1_ds2781_fops = { 142 142 .add_slave = w1_ds2781_add_slave, 143 143 .remove_slave = w1_ds2781_remove_slave, 144 144 .groups = w1_ds2781_groups,
+1 -1
drivers/w1/slaves/w1_ds2805.c
··· 281 281 sysfs_remove_bin_file(&sl->dev.kobj, &w1_f0d_bin_attr); 282 282 } 283 283 284 - static struct w1_family_ops w1_f0d_fops = { 284 + static const struct w1_family_ops w1_f0d_fops = { 285 285 .add_slave = w1_f0d_add_slave, 286 286 .remove_slave = w1_f0d_remove_slave, 287 287 };
+1 -1
drivers/w1/slaves/w1_ds28e04.c
··· 410 410 sl->family_data = NULL; 411 411 } 412 412 413 - static struct w1_family_ops w1_f1C_fops = { 413 + static const struct w1_family_ops w1_f1C_fops = { 414 414 .add_slave = w1_f1C_add_slave, 415 415 .remove_slave = w1_f1C_remove_slave, 416 416 .groups = w1_f1C_groups,
+1 -1
drivers/w1/slaves/w1_ds28e17.c
··· 741 741 742 742 743 743 /* Declarations within the w1 subsystem. */ 744 - static struct w1_family_ops w1_f19_fops = { 744 + static const struct w1_family_ops w1_f19_fops = { 745 745 .add_slave = w1_f19_add_slave, 746 746 .remove_slave = w1_f19_remove_slave, 747 747 .groups = w1_f19_groups,
+3 -3
drivers/w1/slaves/w1_therm.c
··· 475 475 476 476 /* Family operations */ 477 477 478 - static struct w1_family_ops w1_therm_fops = { 478 + static const struct w1_family_ops w1_therm_fops = { 479 479 .add_slave = w1_therm_add_slave, 480 480 .remove_slave = w1_therm_remove_slave, 481 481 .groups = w1_therm_groups, 482 482 .chip_info = W1_CHIPINFO, 483 483 }; 484 484 485 - static struct w1_family_ops w1_ds18s20_fops = { 485 + static const struct w1_family_ops w1_ds18s20_fops = { 486 486 .add_slave = w1_therm_add_slave, 487 487 .remove_slave = w1_therm_remove_slave, 488 488 .groups = w1_ds18s20_groups, 489 489 .chip_info = W1_CHIPINFO, 490 490 }; 491 491 492 - static struct w1_family_ops w1_ds28ea00_fops = { 492 + static const struct w1_family_ops w1_ds28ea00_fops = { 493 493 .add_slave = w1_therm_add_slave, 494 494 .remove_slave = w1_therm_remove_slave, 495 495 .groups = w1_ds28ea00_groups,
+1 -1
drivers/w1/w1.c
··· 160 160 NULL, 161 161 }; 162 162 163 - static struct w1_family_ops w1_default_fops = { 163 + static const struct w1_family_ops w1_default_fops = { 164 164 .groups = w1_slave_default_groups, 165 165 }; 166 166