Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: gadget: configfs: Constify struct config_item_type

'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>

authored by

Christophe JAILLET and committed by
Greg Kroah-Hartman
d1e14e06 c343e66e

+6 -6
+4 -4
drivers/usb/gadget/configfs.c
··· 902 902 .drop_item = gadget_language_string_drop, 903 903 }; 904 904 905 - static struct config_item_type gadget_language_type = { 905 + static const struct config_item_type gadget_language_type = { 906 906 .ct_item_ops = &gadget_language_langid_item_ops, 907 907 .ct_group_ops = &gadget_language_langid_group_ops, 908 908 .ct_attrs = gadget_language_langid_attrs, ··· 961 961 .drop_item = &gadget_language_drop, 962 962 }; 963 963 964 - static struct config_item_type gadget_language_strings_type = { 964 + static const struct config_item_type gadget_language_strings_type = { 965 965 .ct_group_ops = &gadget_language_group_ops, 966 966 .ct_owner = THIS_MODULE, 967 967 }; ··· 1106 1106 NULL, 1107 1107 }; 1108 1108 1109 - static struct config_item_type webusb_type = { 1109 + static const struct config_item_type webusb_type = { 1110 1110 .ct_attrs = webusb_attrs, 1111 1111 .ct_owner = THIS_MODULE, 1112 1112 }; ··· 1263 1263 .drop_link = os_desc_unlink, 1264 1264 }; 1265 1265 1266 - static struct config_item_type os_desc_type = { 1266 + static const struct config_item_type os_desc_type = { 1267 1267 .ct_item_ops = &os_desc_ops, 1268 1268 .ct_attrs = os_desc_attrs, 1269 1269 .ct_owner = THIS_MODULE,
+2 -2
include/linux/usb/gadget_configfs.h
··· 34 34 .release = struct_in##_attr_release, \ 35 35 }; \ 36 36 \ 37 - static struct config_item_type struct_in##_langid_type = { \ 37 + static const struct config_item_type struct_in##_langid_type = { \ 38 38 .ct_item_ops = &struct_in##_langid_item_ops, \ 39 39 .ct_attrs = struct_in##_langid_attrs, \ 40 40 .ct_owner = THIS_MODULE, \ ··· 91 91 .drop_item = &struct_in##_strings_drop, \ 92 92 }; \ 93 93 \ 94 - static struct config_item_type struct_in##_strings_type = { \ 94 + static const struct config_item_type struct_in##_strings_type = { \ 95 95 .ct_group_ops = &struct_in##_strings_ops, \ 96 96 .ct_owner = THIS_MODULE, \ 97 97 }