driver core: class: mark the struct class for sysfs callbacks as constant
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Mar 2023 08:45:37 +0000 (09:45 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Mar 2023 05:54:58 +0000 (07:54 +0200)
struct class should never be modified in a sysfs callback as there is
nothing in the structure to modify, and frankly, the structure is almost
never used in a sysfs callback, so mark it as constant to allow struct
class to be moved to read-only memory.

While we are touching all class sysfs callbacks also mark the attribute
as constant as it can not be modified.  The bonding code still uses this
structure so it can not be removed from the function callbacks.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Steve French <sfrench@samba.org>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-cifs@vger.kernel.org
Cc: linux-gpio@vger.kernel.org
Cc: linux-mtd@lists.infradead.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: netdev@vger.kernel.org
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20230325084537.3622280-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 files changed:
arch/powerpc/platforms/pseries/dlpar.c
arch/powerpc/platforms/pseries/mobility.c
drivers/base/class.c
drivers/base/devcoredump.c
drivers/base/firmware_loader/sysfs.c
drivers/block/pktcdvd.c
drivers/block/zram/zram_drv.c
drivers/gpio/gpiolib-sysfs.c
drivers/infiniband/core/user_mad.c
drivers/mtd/ubi/build.c
drivers/net/bonding/bond_sysfs.c
drivers/s390/crypto/zcrypt_api.c
fs/ksmbd/server.c
include/linux/device/class.h

index 75ffdbcd28659e11741cf8cd7deb8d59ccdc0e48..719c97a155edfab9f5eae927c446bd0f7dad38cf 100644 (file)
@@ -512,7 +512,7 @@ static int dlpar_parse_id_type(char **cmd, struct pseries_hp_errorlog *hp_elog)
        return 0;
 }
 
-static ssize_t dlpar_store(struct class *class, struct class_attribute *attr,
+static ssize_t dlpar_store(const struct class *class, const struct class_attribute *attr,
                           const char *buf, size_t count)
 {
        struct pseries_hp_errorlog hp_elog;
@@ -551,7 +551,7 @@ dlpar_store_out:
        return rc ? rc : count;
 }
 
-static ssize_t dlpar_show(struct class *class, struct class_attribute *attr,
+static ssize_t dlpar_show(const struct class *class, const struct class_attribute *attr,
                          char *buf)
 {
        return sprintf(buf, "%s\n", "memory,cpu");
index 643d309d1bd052f2a37ee6bd2d5a2cec2e849054..6b25642adfa045459c979459b4044e0c9d23f594 100644 (file)
@@ -787,8 +787,8 @@ int rtas_syscall_dispatch_ibm_suspend_me(u64 handle)
        return pseries_migrate_partition(handle);
 }
 
-static ssize_t migration_store(struct class *class,
-                              struct class_attribute *attr, const char *buf,
+static ssize_t migration_store(const struct class *class,
+                              const struct class_attribute *attr, const char *buf,
                               size_t count)
 {
        u64 streamid;
index 8ae91e118827c43719b82c22ad5b99d8a698f5ac..04de20e0dba8694904d2ecfedd8f13cb01370dfe 100644 (file)
@@ -482,8 +482,8 @@ void class_interface_unregister(struct class_interface *class_intf)
 }
 EXPORT_SYMBOL_GPL(class_interface_unregister);
 
-ssize_t show_class_attr_string(struct class *class,
-                              struct class_attribute *attr, char *buf)
+ssize_t show_class_attr_string(const struct class *class,
+                              const struct class_attribute *attr, char *buf)
 {
        struct class_attribute_string *cs;
 
index 59aaf2e1375a6903d79b61e87816598287dd4a46..91536ee05f144eb48fcc43a6a3a0d6f13f4561fa 100644 (file)
@@ -167,7 +167,7 @@ static int devcd_free(struct device *dev, void *data)
        return 0;
 }
 
-static ssize_t disabled_show(struct class *class, struct class_attribute *attr,
+static ssize_t disabled_show(const struct class *class, const struct class_attribute *attr,
                             char *buf)
 {
        return sysfs_emit(buf, "%d\n", devcd_disabled);
@@ -197,7 +197,7 @@ static ssize_t disabled_show(struct class *class, struct class_attribute *attr,
  * so, above situation would not occur.
  */
 
-static ssize_t disabled_store(struct class *class, struct class_attribute *attr,
+static ssize_t disabled_store(const struct class *class, const struct class_attribute *attr,
                              const char *buf, size_t count)
 {
        long tmp = simple_strtol(buf, NULL, 10);
index 56911d75b90a1f8355b8f6ceadf2ed14d32aa00f..c9c93b47d9a519aa2e32e368e4b930dd05d16f0c 100644 (file)
@@ -25,7 +25,7 @@ void __fw_load_abort(struct fw_priv *fw_priv)
 }
 
 #ifdef CONFIG_FW_LOADER_USER_HELPER
-static ssize_t timeout_show(struct class *class, struct class_attribute *attr,
+static ssize_t timeout_show(const struct class *class, const struct class_attribute *attr,
                            char *buf)
 {
        return sysfs_emit(buf, "%d\n", __firmware_loading_timeout());
@@ -44,7 +44,7 @@ static ssize_t timeout_show(struct class *class, struct class_attribute *attr,
  *
  *     Note: zero means 'wait forever'.
  **/
-static ssize_t timeout_store(struct class *class, struct class_attribute *attr,
+static ssize_t timeout_store(const struct class *class, const struct class_attribute *attr,
                             const char *buf, size_t count)
 {
        int tmp_loading_timeout = simple_strtol(buf, NULL, 10);
index 642e3377441af02a7f60999ec4bfcf451ffc28c6..ba9bbdef9ef50ff3d5ae66e85a9a0df0168dd6b1 100644 (file)
@@ -343,7 +343,7 @@ static void class_pktcdvd_release(struct class *cls)
        kfree(cls);
 }
 
-static ssize_t device_map_show(struct class *c, struct class_attribute *attr,
+static ssize_t device_map_show(const struct class *c, const struct class_attribute *attr,
                               char *data)
 {
        int n = 0;
@@ -364,7 +364,7 @@ static ssize_t device_map_show(struct class *c, struct class_attribute *attr,
 }
 static CLASS_ATTR_RO(device_map);
 
-static ssize_t add_store(struct class *c, struct class_attribute *attr,
+static ssize_t add_store(const struct class *c, const struct class_attribute *attr,
                         const char *buf, size_t count)
 {
        unsigned int major, minor;
@@ -385,7 +385,7 @@ static ssize_t add_store(struct class *c, struct class_attribute *attr,
 }
 static CLASS_ATTR_WO(add);
 
-static ssize_t remove_store(struct class *c, struct class_attribute *attr,
+static ssize_t remove_store(const struct class *c, const struct class_attribute *attr,
                            const char *buf, size_t count)
 {
        unsigned int major, minor;
index b7bb52f8dfbdf314a4254e6ae109e8105f920ac2..3feadfb9611426c0b5345299d5837cdca7b20e07 100644 (file)
@@ -2424,8 +2424,8 @@ static int zram_remove(struct zram *zram)
  * creates a new un-initialized zram device and returns back this device's
  * device_id (or an error code if it fails to create a new device).
  */
-static ssize_t hot_add_show(struct class *class,
-                       struct class_attribute *attr,
+static ssize_t hot_add_show(const struct class *class,
+                       const struct class_attribute *attr,
                        char *buf)
 {
        int ret;
@@ -2438,11 +2438,10 @@ static ssize_t hot_add_show(struct class *class,
                return ret;
        return scnprintf(buf, PAGE_SIZE, "%d\n", ret);
 }
-static struct class_attribute class_attr_hot_add =
-       __ATTR(hot_add, 0400, hot_add_show, NULL);
+static CLASS_ATTR_RO(hot_add);
 
-static ssize_t hot_remove_store(struct class *class,
-                       struct class_attribute *attr,
+static ssize_t hot_remove_store(const struct class *class,
+                       const struct class_attribute *attr,
                        const char *buf,
                        size_t count)
 {
index 774755052618aa882b6dad1f7778e11edb1bf541..a895915affa59c43401727004ee3dc90be4585ca 100644 (file)
@@ -426,8 +426,8 @@ ATTRIBUTE_GROUPS(gpiochip);
  * /sys/class/gpio/unexport ... write-only
  *     integer N ... number of GPIO to unexport
  */
-static ssize_t export_store(struct class *class,
-                               struct class_attribute *attr,
+static ssize_t export_store(const struct class *class,
+                               const struct class_attribute *attr,
                                const char *buf, size_t len)
 {
        long                    gpio;
@@ -478,8 +478,8 @@ done:
 }
 static CLASS_ATTR_WO(export);
 
-static ssize_t unexport_store(struct class *class,
-                               struct class_attribute *attr,
+static ssize_t unexport_store(const struct class *class,
+                               const struct class_attribute *attr,
                                const char *buf, size_t len)
 {
        long                    gpio;
index f83954180a338997b7b7775d5d9ab719b5d79fa3..0e9e04f8c6858f83ea06b041ec1a7ca27ed23fa5 100644 (file)
@@ -1229,8 +1229,8 @@ static char *umad_devnode(const struct device *dev, umode_t *mode)
        return kasprintf(GFP_KERNEL, "infiniband/%s", dev_name(dev));
 }
 
-static ssize_t abi_version_show(struct class *class,
-                               struct class_attribute *attr, char *buf)
+static ssize_t abi_version_show(const struct class *class,
+                               const struct class_attribute *attr, char *buf)
 {
        return sysfs_emit(buf, "%d\n", IB_USER_MAD_ABI_VERSION);
 }
index ae6d35e3da9c00b45b4642e4009d5ca5db1b61d4..32105bd3583172775aeb8fa1326bb4f96687fb21 100644 (file)
@@ -95,7 +95,7 @@ static DEFINE_SPINLOCK(ubi_devices_lock);
 
 /* "Show" method for files in '/<sysfs>/class/ubi/' */
 /* UBI version attribute ('/<sysfs>/class/ubi/version') */
-static ssize_t version_show(struct class *class, struct class_attribute *attr,
+static ssize_t version_show(const struct class *class, const struct class_attribute *attr,
                            char *buf)
 {
        return sprintf(buf, "%d\n", UBI_VERSION);
index 8996bd0a194ab6ea2c5aaa1591f956201fcd07dd..0bb59da2492247546dc210822e326f89777da0f3 100644 (file)
 /* "show" function for the bond_masters attribute.
  * The class parameter is ignored.
  */
-static ssize_t bonding_show_bonds(struct class *cls,
-                                 struct class_attribute *attr,
+static ssize_t bonding_show_bonds(const struct class *cls,
+                                 const struct class_attribute *attr,
                                  char *buf)
 {
-       struct bond_net *bn =
-               container_of(attr, struct bond_net, class_attr_bonding_masters);
+       const struct bond_net *bn =
+               container_of_const(attr, struct bond_net, class_attr_bonding_masters);
        int res = 0;
        struct bonding *bond;
 
@@ -59,7 +59,7 @@ static ssize_t bonding_show_bonds(struct class *cls,
        return res;
 }
 
-static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
+static struct net_device *bond_get_by_name(const struct bond_net *bn, const char *ifname)
 {
        struct bonding *bond;
 
@@ -75,12 +75,12 @@ static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifna
  *
  * The class parameter is ignored.
  */
-static ssize_t bonding_store_bonds(struct class *cls,
-                                  struct class_attribute *attr,
+static ssize_t bonding_store_bonds(const struct class *cls,
+                                  const struct class_attribute *attr,
                                   const char *buffer, size_t count)
 {
-       struct bond_net *bn =
-               container_of(attr, struct bond_net, class_attr_bonding_masters);
+       const struct bond_net *bn =
+               container_of_const(attr, struct bond_net, class_attr_bonding_masters);
        char command[IFNAMSIZ + 1] = {0, };
        char *ifname;
        int rv, res = count;
index 582ac301d31502966cd04c5f334e029c3c27dcc2..cff2eea88f98dee58d9816941c07007f109c1e07 100644 (file)
@@ -340,8 +340,8 @@ static const struct attribute_group *zcdn_dev_attr_groups[] = {
        NULL
 };
 
-static ssize_t zcdn_create_store(struct class *class,
-                                struct class_attribute *attr,
+static ssize_t zcdn_create_store(const struct class *class,
+                                const struct class_attribute *attr,
                                 const char *buf, size_t count)
 {
        int rc;
@@ -357,8 +357,8 @@ static ssize_t zcdn_create_store(struct class *class,
 static const struct class_attribute class_attr_zcdn_create =
        __ATTR(create, 0600, NULL, zcdn_create_store);
 
-static ssize_t zcdn_destroy_store(struct class *class,
-                                 struct class_attribute *attr,
+static ssize_t zcdn_destroy_store(const struct class *class,
+                                 const struct class_attribute *attr,
                                  const char *buf, size_t count)
 {
        int rc;
index b5af3e43e6770eaf8ce60c44edabc061c27d84f6..c2c958a5423ea4a2a899ef2c1b1c9a17e26a2066 100644 (file)
@@ -418,7 +418,7 @@ int server_queue_ctrl_reset_work(void)
        return __queue_ctrl_work(SERVER_CTRL_TYPE_RESET);
 }
 
-static ssize_t stats_show(struct class *class, struct class_attribute *attr,
+static ssize_t stats_show(const struct class *class, const struct class_attribute *attr,
                          char *buf)
 {
        /*
@@ -437,8 +437,8 @@ static ssize_t stats_show(struct class *class, struct class_attribute *attr,
                          server_conf.ipc_last_active / HZ);
 }
 
-static ssize_t kill_server_store(struct class *class,
-                                struct class_attribute *attr, const char *buf,
+static ssize_t kill_server_store(const struct class *class,
+                                const struct class_attribute *attr, const char *buf,
                                 size_t len)
 {
        if (!sysfs_streq(buf, "hard"))
@@ -458,7 +458,7 @@ static const char * const debug_type_strings[] = {"smb", "auth", "vfs",
                                                  "oplock", "ipc", "conn",
                                                  "rdma"};
 
-static ssize_t debug_show(struct class *class, struct class_attribute *attr,
+static ssize_t debug_show(const struct class *class, const struct class_attribute *attr,
                          char *buf)
 {
        ssize_t sz = 0;
@@ -476,7 +476,7 @@ static ssize_t debug_show(struct class *class, struct class_attribute *attr,
        return sz;
 }
 
-static ssize_t debug_store(struct class *class, struct class_attribute *attr,
+static ssize_t debug_store(const struct class *class, const struct class_attribute *attr,
                           const char *buf, size_t len)
 {
        int i;
index 73436c578d373315904278ffd80c8227a890ef63..b53728ca56fbcaaf5019fa9ddb01f56e064f8d38 100644 (file)
@@ -174,10 +174,10 @@ static inline struct device *class_find_device_by_acpi_dev(const struct class *c
 
 struct class_attribute {
        struct attribute attr;
-       ssize_t (*show)(struct class *class, struct class_attribute *attr,
+       ssize_t (*show)(const struct class *class, const struct class_attribute *attr,
                        char *buf);
-       ssize_t (*store)(struct class *class, struct class_attribute *attr,
-                       const char *buf, size_t count);
+       ssize_t (*store)(const struct class *class, const struct class_attribute *attr,
+                        const char *buf, size_t count);
 };
 
 #define CLASS_ATTR_RW(_name) \
@@ -217,7 +217,8 @@ struct class_attribute_string {
        struct class_attribute_string class_attr_##_name = \
                _CLASS_ATTR_STRING(_name, _mode, _str)
 
-ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr, char *buf);
+ssize_t show_class_attr_string(const struct class *class, const struct class_attribute *attr,
+                              char *buf);
 
 struct class_interface {
        struct list_head        node;