w1: Constify static w1_family_ops structs
authorRikard Falkeborn <rikard.falkeborn@gmail.com>
Sun, 4 Oct 2020 19:32:01 +0000 (21:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Oct 2020 11:21:49 +0000 (13:21 +0200)
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>
17 files changed:
drivers/w1/slaves/w1_ds2405.c
drivers/w1/slaves/w1_ds2406.c
drivers/w1/slaves/w1_ds2408.c
drivers/w1/slaves/w1_ds2413.c
drivers/w1/slaves/w1_ds2423.c
drivers/w1/slaves/w1_ds2430.c
drivers/w1/slaves/w1_ds2431.c
drivers/w1/slaves/w1_ds2433.c
drivers/w1/slaves/w1_ds2438.c
drivers/w1/slaves/w1_ds250x.c
drivers/w1/slaves/w1_ds2780.c
drivers/w1/slaves/w1_ds2781.c
drivers/w1/slaves/w1_ds2805.c
drivers/w1/slaves/w1_ds28e04.c
drivers/w1/slaves/w1_ds28e17.c
drivers/w1/slaves/w1_therm.c
drivers/w1/w1.c

index 86cd97309d877d499748c6f38ce285e5653862b2..1d9a1183e83f52b7264cf497862d1ed71681b339 100644 (file)
@@ -206,7 +206,7 @@ static struct attribute *w1_ds2405_attrs[] = {
 
 ATTRIBUTE_GROUPS(w1_ds2405);
 
-static struct w1_family_ops w1_ds2405_fops = {
+static const struct w1_family_ops w1_ds2405_fops = {
        .groups = w1_ds2405_groups
 };
 
index 762e5e4e2b4883abc2e4d274cb18fe9612f25339..6c269af73c80e56713f023cb1bca18603f36d2da 100644 (file)
@@ -138,7 +138,7 @@ static void w1_f12_remove_slave(struct w1_slave *sl)
                        &(w1_f12_sysfs_bin_files[i]));
 }
 
-static struct w1_family_ops w1_f12_fops = {
+static const struct w1_family_ops w1_f12_fops = {
        .add_slave      = w1_f12_add_slave,
        .remove_slave   = w1_f12_remove_slave,
 };
index 83f8d94bb814f98e73d3cfd8e97cf1efee43ad29..ad102c5771222eb9d933970bcafe87a4647046a3 100644 (file)
@@ -336,7 +336,7 @@ static const struct attribute_group *w1_f29_groups[] = {
        NULL,
 };
 
-static struct w1_family_ops w1_f29_fops = {
+static const struct w1_family_ops w1_f29_fops = {
        .add_slave      = w1_f29_disable_test_mode,
        .groups         = w1_f29_groups,
 };
index f1fb18afbcea035ce5b1bebc0df13ed26ce6a6ee..c8cfac555b48831fd0bf2a56df3031e7543ad66f 100644 (file)
@@ -143,7 +143,7 @@ static const struct attribute_group *w1_f3a_groups[] = {
        NULL,
 };
 
-static struct w1_family_ops w1_f3a_fops = {
+static const struct w1_family_ops w1_f3a_fops = {
        .groups         = w1_f3a_groups,
 };
 
index f4367282dcc191461a3843ea498bfd239d6c8254..b6bd18d5b3f62de3c993f3a8e3f4df04cab7a4da 100644 (file)
@@ -117,7 +117,7 @@ static struct attribute *w1_f1d_attrs[] = {
 };
 ATTRIBUTE_GROUPS(w1_f1d);
 
-static struct w1_family_ops w1_f1d_fops = {
+static const struct w1_family_ops w1_f1d_fops = {
        .groups         = w1_f1d_groups,
 };
 
index 75bb8a88620b7b121415fcc7d5b331f2108bf481..0ea7d779d17aecf8cbdd19320a6df6070ed9d507 100644 (file)
@@ -279,7 +279,7 @@ static const struct attribute_group *w1_f14_groups[] = {
        NULL,
 };
 
-static struct w1_family_ops w1_f14_fops = {
+static const struct w1_family_ops w1_f14_fops = {
        .groups = w1_f14_groups,
 };
 
index e5bd7e2354d7fe5de69d117beaf36cd49e4bfc7f..6856b1c29e179afe072ff06b94b3ba86759c7fcc 100644 (file)
@@ -278,7 +278,7 @@ static const struct attribute_group *w1_f2d_groups[] = {
        NULL,
 };
 
-static struct w1_family_ops w1_f2d_fops = {
+static const struct w1_family_ops w1_f2d_fops = {
        .groups         = w1_f2d_groups,
 };
 
index 1f805c86517a7799c295ba8470e4da58aa010108..0f72df15a0244ea8fb5ec7b5a693242b6ac2a999 100644 (file)
@@ -288,7 +288,7 @@ static void w1_f23_remove_slave(struct w1_slave *sl)
 #endif /* CONFIG_W1_SLAVE_DS2433_CRC */
 }
 
-static struct w1_family_ops w1_f23_fops = {
+static const struct w1_family_ops w1_f23_fops = {
        .add_slave      = w1_f23_add_slave,
        .remove_slave   = w1_f23_remove_slave,
        .groups         = w1_f23_groups,
index d199e5a25cc000ab5f9c46126c95f08f7ee2a26f..5cfb0ae23e916c78e1f34bc4754b42071134cf1f 100644 (file)
@@ -412,7 +412,7 @@ static const struct attribute_group *w1_ds2438_groups[] = {
        NULL,
 };
 
-static struct w1_family_ops w1_ds2438_fops = {
+static const struct w1_family_ops w1_ds2438_fops = {
        .groups         = w1_ds2438_groups,
 };
 
index e507117444d8332ca4e2da2f8e63662e2486a386..7592c7050d1d7de19ecad038603acab3f74324f3 100644 (file)
@@ -215,7 +215,7 @@ static int w1_eprom_add_slave(struct w1_slave *sl)
        return PTR_ERR_OR_ZERO(nvmem);
 }
 
-static struct w1_family_ops w1_eprom_fops = {
+static const struct w1_family_ops w1_eprom_fops = {
        .add_slave      = w1_eprom_add_slave,
 };
 
index c689b1b987b89521e72002adf513594eac1f1209..c281fe5ed68875eab8bbb1d22fae02650b2d4f31 100644 (file)
@@ -141,7 +141,7 @@ static void w1_ds2780_remove_slave(struct w1_slave *sl)
        platform_device_unregister(pdev);
 }
 
-static struct w1_family_ops w1_ds2780_fops = {
+static const struct w1_family_ops w1_ds2780_fops = {
        .add_slave    = w1_ds2780_add_slave,
        .remove_slave = w1_ds2780_remove_slave,
        .groups       = w1_ds2780_groups,
index 84d6ceec5da5bcb16294752be7ac3a9e52070998..f0d393ae070b87a7b3bbd10f5456fb4114793984 100644 (file)
@@ -138,7 +138,7 @@ static void w1_ds2781_remove_slave(struct w1_slave *sl)
        platform_device_unregister(pdev);
 }
 
-static struct w1_family_ops w1_ds2781_fops = {
+static const struct w1_family_ops w1_ds2781_fops = {
        .add_slave    = w1_ds2781_add_slave,
        .remove_slave = w1_ds2781_remove_slave,
        .groups       = w1_ds2781_groups,
index ccb753a474b18c64799e7f6445a67a66cf48666e..206186db727d4f184ca99cfc538e508cebcdd8d1 100644 (file)
@@ -281,7 +281,7 @@ static void w1_f0d_remove_slave(struct w1_slave *sl)
        sysfs_remove_bin_file(&sl->dev.kobj, &w1_f0d_bin_attr);
 }
 
-static struct w1_family_ops w1_f0d_fops = {
+static const struct w1_family_ops w1_f0d_fops = {
        .add_slave      = w1_f0d_add_slave,
        .remove_slave   = w1_f0d_remove_slave,
 };
index 8a640f1590784637cd4cb5feac89d94562e685e4..e4f336111edc6feb51cf0c602b19585bed1b87a5 100644 (file)
@@ -410,7 +410,7 @@ static void w1_f1C_remove_slave(struct w1_slave *sl)
        sl->family_data = NULL;
 }
 
-static struct w1_family_ops w1_f1C_fops = {
+static const struct w1_family_ops w1_f1C_fops = {
        .add_slave      = w1_f1C_add_slave,
        .remove_slave   = w1_f1C_remove_slave,
        .groups         = w1_f1C_groups,
index 046ddda83df94b6df656bcf05a7e8c105aea103d..6b00db7169ab311d3f0c9b707fd0a6422fbbb058 100644 (file)
@@ -741,7 +741,7 @@ static void w1_f19_remove_slave(struct w1_slave *sl)
 
 
 /* Declarations within the w1 subsystem. */
-static struct w1_family_ops w1_f19_fops = {
+static const struct w1_family_ops w1_f19_fops = {
        .add_slave = w1_f19_add_slave,
        .remove_slave = w1_f19_remove_slave,
        .groups = w1_f19_groups,
index f6b0e0320ffca7a88bc6ea211c61446b4401a59d..e4baaf92f0748aa48dfb953e65001094cca19803 100644 (file)
@@ -475,21 +475,21 @@ static const struct hwmon_chip_info w1_chip_info = {
 
 /* Family operations */
 
-static struct w1_family_ops w1_therm_fops = {
+static const struct w1_family_ops w1_therm_fops = {
        .add_slave      = w1_therm_add_slave,
        .remove_slave   = w1_therm_remove_slave,
        .groups         = w1_therm_groups,
        .chip_info      = W1_CHIPINFO,
 };
 
-static struct w1_family_ops w1_ds18s20_fops = {
+static const struct w1_family_ops w1_ds18s20_fops = {
        .add_slave      = w1_therm_add_slave,
        .remove_slave   = w1_therm_remove_slave,
        .groups         = w1_ds18s20_groups,
        .chip_info      = W1_CHIPINFO,
 };
 
-static struct w1_family_ops w1_ds28ea00_fops = {
+static const struct w1_family_ops w1_ds28ea00_fops = {
        .add_slave      = w1_therm_add_slave,
        .remove_slave   = w1_therm_remove_slave,
        .groups         = w1_ds28ea00_groups,
index 6bd64bcb6316e5605cb59ba4c0bd4745a8f4e02c..15a2ee32f116ea9e7801a8047c9c492ae91a5b89 100644 (file)
@@ -160,7 +160,7 @@ static const struct attribute_group *w1_slave_default_groups[] = {
        NULL,
 };
 
-static struct w1_family_ops w1_default_fops = {
+static const struct w1_family_ops w1_default_fops = {
        .groups         = w1_slave_default_groups,
 };