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 86cd973..1d9a118 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 762e5e4..6c269af 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 83f8d94..ad102c5 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 f1fb18a..c8cfac5 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 f436728..b6bd18d 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 75bb8a8..0ea7d77 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 e5bd7e2..6856b1c 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 1f805c8..0f72df1 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 d199e5a..5cfb0ae 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 e507117..7592c70 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 c689b1b..c281fe5 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 84d6cee..f0d393a 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 ccb753a..206186d 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 8a640f1..e4f3361 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 046ddda..6b00db7 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 f6b0e03..e4baaf9 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 6bd64bc..15a2ee3 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,
 };