]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
samples: configfs: Constify struct configfs_item_operations and configfs_group_operations
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Mon, 29 Dec 2025 11:23:51 +0000 (12:23 +0100)
committerAndreas Hindborg <a.hindborg@kernel.org>
Thu, 15 Jan 2026 08:27:27 +0000 (09:27 +0100)
'struct configfs_item_operations' and 'configfs_group_operations' are not
modified in this driver.

Constifying these structures moves some data to a read-only section, so
increases overall security, especially when the structure holds some
function pointers.

On a x86_64, with allmodconfig:
Before:
======
   text    data     bss     dec     hex filename
   7507    6504      64   14075    36fb samples/configfs/configfs_sample.o

After:
=====
   text    data     bss     dec     hex filename
   7827    6184      64   14075    36fb samples/configfs/configfs_sample.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/70c5fd68fcc4d3ba1f18002012fae19acf4ce50b.1767007414.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
samples/configfs/configfs_sample.c

index fd5d163828c52f962fe3c4be2f82dfce4571274f..c1b108ec4ea02e63269be47494a1dbc311e2a073 100644 (file)
@@ -158,7 +158,7 @@ static void simple_child_release(struct config_item *item)
        kfree(to_simple_child(item));
 }
 
-static struct configfs_item_operations simple_child_item_ops = {
+static const struct configfs_item_operations simple_child_item_ops = {
        .release        = simple_child_release,
 };
 
@@ -215,7 +215,7 @@ static void simple_children_release(struct config_item *item)
        kfree(to_simple_children(item));
 }
 
-static struct configfs_item_operations simple_children_item_ops = {
+static const struct configfs_item_operations simple_children_item_ops = {
        .release        = simple_children_release,
 };
 
@@ -223,7 +223,7 @@ static struct configfs_item_operations simple_children_item_ops = {
  * Note that, since no extra work is required on ->drop_item(),
  * no ->drop_item() is provided.
  */
-static struct configfs_group_operations simple_children_group_ops = {
+static const struct configfs_group_operations simple_children_group_ops = {
        .make_item      = simple_children_make_item,
 };
 
@@ -292,7 +292,7 @@ static struct configfs_attribute *group_children_attrs[] = {
  * Note that, since no extra work is required on ->drop_item(),
  * no ->drop_item() is provided.
  */
-static struct configfs_group_operations group_children_group_ops = {
+static const struct configfs_group_operations group_children_group_ops = {
        .make_group     = group_children_make_group,
 };