]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: gadget: configfs: Constify struct config_item_type
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 10 Aug 2024 21:05:46 +0000 (23:05 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Aug 2024 08:38:34 +0000 (10:38 +0200)
'struct config_item_type' is not modified in this file.

Apparently, these structures are only used with
config_group_init_type_name() which takes a const struct config_item_type*
as a 3rd argument.

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

On a x86_64, with allmodconfig:
Before:
======
   text    data     bss     dec     hex filename
  40834    5112      64   46010    b3ba drivers/usb/gadget/configfs.o

After:
=====
   text    data     bss     dec     hex filename
  41218    4728      64   46010    b3ba drivers/usb/gadget/configfs.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/513223e97082e1bb758e36d55c175ec9ea34a71c.1723323896.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/configfs.c
include/linux/usb/gadget_configfs.h

index e0bf2b2bfc01dbdeadf46aaa6772247da3dca3f7..5cba3e8d626c5aeab149e155d8f5387909a03798 100644 (file)
@@ -902,7 +902,7 @@ static struct configfs_group_operations gadget_language_langid_group_ops = {
        .drop_item              = gadget_language_string_drop,
 };
 
-static struct config_item_type gadget_language_type = {
+static const struct config_item_type gadget_language_type = {
        .ct_item_ops    = &gadget_language_langid_item_ops,
        .ct_group_ops   = &gadget_language_langid_group_ops,
        .ct_attrs       = gadget_language_langid_attrs,
@@ -961,7 +961,7 @@ static struct configfs_group_operations gadget_language_group_ops = {
        .drop_item      = &gadget_language_drop,
 };
 
-static struct config_item_type gadget_language_strings_type = {
+static const struct config_item_type gadget_language_strings_type = {
        .ct_group_ops   = &gadget_language_group_ops,
        .ct_owner       = THIS_MODULE,
 };
@@ -1106,7 +1106,7 @@ static struct configfs_attribute *webusb_attrs[] = {
        NULL,
 };
 
-static struct config_item_type webusb_type = {
+static const struct config_item_type webusb_type = {
        .ct_attrs       = webusb_attrs,
        .ct_owner       = THIS_MODULE,
 };
@@ -1263,7 +1263,7 @@ static struct configfs_item_operations os_desc_ops = {
        .drop_link              = os_desc_unlink,
 };
 
-static struct config_item_type os_desc_type = {
+static const struct config_item_type os_desc_type = {
        .ct_item_ops    = &os_desc_ops,
        .ct_attrs       = os_desc_attrs,
        .ct_owner       = THIS_MODULE,
index 6a552dd4dec94f628fb9e06a49ea873a1feaeb24..6b5d6838f86528d55092ad7d1b238acf80827804 100644 (file)
@@ -34,7 +34,7 @@ static struct configfs_item_operations struct_in##_langid_item_ops = {        \
        .release                = struct_in##_attr_release,             \
 };                                                                     \
                                                                        \
-static struct config_item_type struct_in##_langid_type = {             \
+static const struct config_item_type struct_in##_langid_type = {       \
        .ct_item_ops    = &struct_in##_langid_item_ops,                 \
        .ct_attrs       = struct_in##_langid_attrs,                     \
        .ct_owner       = THIS_MODULE,                                  \
@@ -91,7 +91,7 @@ static struct configfs_group_operations struct_in##_strings_ops = {   \
        .drop_item      = &struct_in##_strings_drop,                    \
 };                                                                     \
                                                                        \
-static struct config_item_type struct_in##_strings_type = {            \
+static const struct config_item_type struct_in##_strings_type = {      \
        .ct_group_ops   = &struct_in##_strings_ops,                     \
        .ct_owner       = THIS_MODULE,                                  \
 }