]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/slab: constify sysfs attributes
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 23 Feb 2026 21:37:44 +0000 (22:37 +0100)
committerVlastimil Babka (SUSE) <vbabka@kernel.org>
Thu, 26 Feb 2026 14:25:06 +0000 (15:25 +0100)
These attributes are never modified, make them read-only.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Link: https://patch.msgid.link/20260223-sysfs-const-slub-v1-2-ff86ffc26fff@weissschuh.net
Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
mm/slub.c

index a48ea23b17282fcae6bf4ee914ed520f2eb10b04..73051cf77353bb8d4e6779ca04e256d41f9dc8ce 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -8833,7 +8833,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
        return len;
 }
 
-#define to_slab_attr(n) container_of(n, struct slab_attribute, attr)
+#define to_slab_attr(n) container_of_const(n, struct slab_attribute, attr)
 #define to_slab(n) container_of(n, struct kmem_cache, kobj)
 
 struct slab_attribute {
@@ -8843,10 +8843,10 @@ struct slab_attribute {
 };
 
 #define SLAB_ATTR_RO(_name) \
-       static struct slab_attribute _name##_attr = __ATTR_RO_MODE(_name, 0400)
+       static const struct slab_attribute _name##_attr = __ATTR_RO_MODE(_name, 0400)
 
 #define SLAB_ATTR(_name) \
-       static struct slab_attribute _name##_attr = __ATTR_RW_MODE(_name, 0600)
+       static const struct slab_attribute _name##_attr = __ATTR_RW_MODE(_name, 0600)
 
 static ssize_t slab_size_show(struct kmem_cache *s, char *buf)
 {
@@ -9240,7 +9240,7 @@ static ssize_t skip_kfence_store(struct kmem_cache *s,
 SLAB_ATTR(skip_kfence);
 #endif
 
-static struct attribute *slab_attrs[] = {
+static const struct attribute *const slab_attrs[] = {
        &slab_size_attr.attr,
        &object_size_attr.attr,
        &objs_per_slab_attr.attr,
@@ -9323,7 +9323,7 @@ static ssize_t slab_attr_show(struct kobject *kobj,
                                struct attribute *attr,
                                char *buf)
 {
-       struct slab_attribute *attribute;
+       const struct slab_attribute *attribute;
        struct kmem_cache *s;
 
        attribute = to_slab_attr(attr);
@@ -9339,7 +9339,7 @@ static ssize_t slab_attr_store(struct kobject *kobj,
                                struct attribute *attr,
                                const char *buf, size_t len)
 {
-       struct slab_attribute *attribute;
+       const struct slab_attribute *attribute;
        struct kmem_cache *s;
 
        attribute = to_slab_attr(attr);