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: Constify struct configfs_item_operations and configfs_group_operations

'struct configfs_item_operations' and 'configfs_group_operations' are not
modified in these drivers.

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, as an example:
Before:
======
text data bss dec hex filename
65061 20968 256 86285 1510d drivers/usb/gadget/configfs.o

After:
=====
text data bss dec hex filename
66181 19848 256 86285 1510d drivers/usb/gadget/configfs.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://patch.msgid.link/49cec1cb84425f854de80b6d69b53a5a3cda8189.1766164523.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Christophe JAILLET and committed by
Greg Kroah-Hartman
e715bc42 dd1fbe32

+55 -55
+12 -12
drivers/usb/gadget/configfs.c
··· 409 409 kfree(gi); 410 410 } 411 411 412 - static struct configfs_item_operations gadget_root_item_ops = { 412 + static const struct configfs_item_operations gadget_root_item_ops = { 413 413 .release = gadget_info_attr_release, 414 414 }; 415 415 ··· 514 514 WARN(1, "Unable to locate function to unbind\n"); 515 515 } 516 516 517 - static struct configfs_item_operations gadget_config_item_ops = { 517 + static const struct configfs_item_operations gadget_config_item_ops = { 518 518 .release = gadget_config_attr_release, 519 519 .allow_link = config_usb_cfg_link, 520 520 .drop_link = config_usb_cfg_unlink, ··· 663 663 config_item_put(item); 664 664 } 665 665 666 - static struct configfs_group_operations functions_ops = { 666 + static const struct configfs_group_operations functions_ops = { 667 667 .make_group = &function_make, 668 668 .drop_item = &function_drop, 669 669 }; ··· 766 766 config_item_put(item); 767 767 } 768 768 769 - static struct configfs_group_operations config_desc_ops = { 769 + static const struct configfs_group_operations config_desc_ops = { 770 770 .make_group = &config_desc_make, 771 771 .drop_item = &config_desc_drop, 772 772 }; ··· 799 799 kfree(gs); 800 800 } 801 801 802 - static struct configfs_item_operations gadget_language_langid_item_ops = { 802 + static const struct configfs_item_operations gadget_language_langid_item_ops = { 803 803 .release = gadget_language_attr_release, 804 804 }; 805 805 ··· 852 852 kfree(string); 853 853 } 854 854 855 - static struct configfs_item_operations gadget_string_item_ops = { 855 + static const struct configfs_item_operations gadget_string_item_ops = { 856 856 .release = gadget_string_release, 857 857 }; 858 858 ··· 901 901 string->usb_string.id = i++; 902 902 } 903 903 904 - static struct configfs_group_operations gadget_language_langid_group_ops = { 904 + static const struct configfs_group_operations gadget_language_langid_group_ops = { 905 905 .make_item = gadget_language_string_make, 906 906 .drop_item = gadget_language_string_drop, 907 907 }; ··· 960 960 config_item_put(item); 961 961 } 962 962 963 - static struct configfs_group_operations gadget_language_group_ops = { 963 + static const struct configfs_group_operations gadget_language_group_ops = { 964 964 .make_group = &gadget_language_make, 965 965 .drop_item = &gadget_language_drop, 966 966 }; ··· 1266 1266 mutex_unlock(&gi->lock); 1267 1267 } 1268 1268 1269 - static struct configfs_item_operations os_desc_ops = { 1269 + static const struct configfs_item_operations os_desc_ops = { 1270 1270 .allow_link = os_desc_link, 1271 1271 .drop_link = os_desc_unlink, 1272 1272 }; ··· 1391 1391 kfree(ext_prop); /* frees a whole chunk */ 1392 1392 } 1393 1393 1394 - static struct configfs_item_operations ext_prop_ops = { 1394 + static const struct configfs_item_operations ext_prop_ops = { 1395 1395 .release = usb_os_desc_ext_prop_release, 1396 1396 }; 1397 1397 ··· 1456 1456 config_item_put(item); 1457 1457 } 1458 1458 1459 - static struct configfs_group_operations interf_grp_ops = { 1459 + static const struct configfs_group_operations interf_grp_ops = { 1460 1460 .make_item = &ext_prop_make, 1461 1461 .drop_item = &ext_prop_drop, 1462 1462 }; ··· 2061 2061 config_item_put(item); 2062 2062 } 2063 2063 2064 - static struct configfs_group_operations gadgets_ops = { 2064 + static const struct configfs_group_operations gadgets_ops = { 2065 2065 .make_group = &gadgets_make, 2066 2066 .drop_item = &gadgets_drop, 2067 2067 };
+1 -1
drivers/usb/gadget/function/f_acm.c
··· 793 793 usb_put_function_instance(&opts->func_inst); 794 794 } 795 795 796 - static struct configfs_item_operations acm_item_ops = { 796 + static const struct configfs_item_operations acm_item_ops = { 797 797 .release = acm_attr_release, 798 798 }; 799 799
+1 -1
drivers/usb/gadget/function/f_fs.c
··· 4004 4004 usb_put_function_instance(&opts->func_inst); 4005 4005 } 4006 4006 4007 - static struct configfs_item_operations ffs_item_ops = { 4007 + static const struct configfs_item_operations ffs_item_ops = { 4008 4008 .release = ffs_attr_release, 4009 4009 }; 4010 4010
+1 -1
drivers/usb/gadget/function/f_hid.c
··· 1328 1328 usb_put_function_instance(&opts->func_inst); 1329 1329 } 1330 1330 1331 - static struct configfs_item_operations hidg_item_ops = { 1331 + static const struct configfs_item_operations hidg_item_ops = { 1332 1332 .release = hid_attr_release, 1333 1333 }; 1334 1334
+1 -1
drivers/usb/gadget/function/f_loopback.c
··· 464 464 usb_put_function_instance(&lb_opts->func_inst); 465 465 } 466 466 467 - static struct configfs_item_operations lb_item_ops = { 467 + static const struct configfs_item_operations lb_item_ops = { 468 468 .release = lb_attr_release, 469 469 }; 470 470
+3 -3
drivers/usb/gadget/function/f_mass_storage.c
··· 3153 3153 kfree(lun_opts); 3154 3154 } 3155 3155 3156 - static struct configfs_item_operations fsg_lun_item_ops = { 3156 + static const struct configfs_item_operations fsg_lun_item_ops = { 3157 3157 .release = fsg_lun_attr_release, 3158 3158 }; 3159 3159 ··· 3369 3369 usb_put_function_instance(&opts->func_inst); 3370 3370 } 3371 3371 3372 - static struct configfs_item_operations fsg_item_ops = { 3372 + static const struct configfs_item_operations fsg_item_ops = { 3373 3373 .release = fsg_attr_release, 3374 3374 }; 3375 3375 ··· 3462 3462 NULL, 3463 3463 }; 3464 3464 3465 - static struct configfs_group_operations fsg_group_ops = { 3465 + static const struct configfs_group_operations fsg_group_ops = { 3466 3466 .make_group = fsg_lun_make, 3467 3467 .drop_item = fsg_lun_drop, 3468 3468 };
+1 -1
drivers/usb/gadget/function/f_midi.c
··· 1091 1091 usb_put_function_instance(&opts->func_inst); 1092 1092 } 1093 1093 1094 - static struct configfs_item_operations midi_item_ops = { 1094 + static const struct configfs_item_operations midi_item_ops = { 1095 1095 .release = midi_attr_release, 1096 1096 }; 1097 1097
+5 -5
drivers/usb/gadget/function/f_midi2.c
··· 2316 2316 kfree(opts); 2317 2317 } 2318 2318 2319 - static struct configfs_item_operations f_midi2_block_item_ops = { 2319 + static const struct configfs_item_operations f_midi2_block_item_ops = { 2320 2320 .release = f_midi2_block_opts_release, 2321 2321 }; 2322 2322 ··· 2479 2479 kfree(opts); 2480 2480 } 2481 2481 2482 - static struct configfs_item_operations f_midi2_ep_item_ops = { 2482 + static const struct configfs_item_operations f_midi2_ep_item_ops = { 2483 2483 .release = f_midi2_ep_opts_release, 2484 2484 }; 2485 2485 2486 - static struct configfs_group_operations f_midi2_ep_group_ops = { 2486 + static const struct configfs_group_operations f_midi2_ep_group_ops = { 2487 2487 .make_group = f_midi2_opts_block_make, 2488 2488 .drop_item = f_midi2_opts_block_drop, 2489 2489 }; ··· 2618 2618 usb_put_function_instance(&opts->func_inst); 2619 2619 } 2620 2620 2621 - static struct configfs_item_operations f_midi2_item_ops = { 2621 + static const struct configfs_item_operations f_midi2_item_ops = { 2622 2622 .release = f_midi2_opts_release, 2623 2623 }; 2624 2624 2625 - static struct configfs_group_operations f_midi2_group_ops = { 2625 + static const struct configfs_group_operations f_midi2_group_ops = { 2626 2626 .make_group = f_midi2_opts_ep_make, 2627 2627 .drop_item = f_midi2_opts_ep_drop, 2628 2628 };
+1 -1
drivers/usb/gadget/function/f_obex.c
··· 390 390 usb_put_function_instance(&opts->func_inst); 391 391 } 392 392 393 - static struct configfs_item_operations obex_item_ops = { 393 + static const struct configfs_item_operations obex_item_ops = { 394 394 .release = obex_attr_release, 395 395 }; 396 396
+1 -1
drivers/usb/gadget/function/f_phonet.c
··· 585 585 usb_put_function_instance(&opts->func_inst); 586 586 } 587 587 588 - static struct configfs_item_operations phonet_item_ops = { 588 + static const struct configfs_item_operations phonet_item_ops = { 589 589 .release = phonet_attr_release, 590 590 }; 591 591
+1 -1
drivers/usb/gadget/function/f_printer.c
··· 1220 1220 usb_put_function_instance(&opts->func_inst); 1221 1221 } 1222 1222 1223 - static struct configfs_item_operations printer_item_ops = { 1223 + static const struct configfs_item_operations printer_item_ops = { 1224 1224 .release = printer_attr_release, 1225 1225 }; 1226 1226
+1 -1
drivers/usb/gadget/function/f_serial.c
··· 260 260 usb_put_function_instance(&opts->func_inst); 261 261 } 262 262 263 - static struct configfs_item_operations serial_item_ops = { 263 + static const struct configfs_item_operations serial_item_ops = { 264 264 .release = serial_attr_release, 265 265 }; 266 266
+1 -1
drivers/usb/gadget/function/f_sourcesink.c
··· 882 882 usb_put_function_instance(&ss_opts->func_inst); 883 883 } 884 884 885 - static struct configfs_item_operations ss_item_ops = { 885 + static const struct configfs_item_operations ss_item_ops = { 886 886 .release = ss_attr_release, 887 887 }; 888 888
+1 -1
drivers/usb/gadget/function/f_tcm.c
··· 2446 2446 usb_put_function_instance(&opts->func_inst); 2447 2447 } 2448 2448 2449 - static struct configfs_item_operations tcm_item_ops = { 2449 + static const struct configfs_item_operations tcm_item_ops = { 2450 2450 .release = tcm_attr_release, 2451 2451 }; 2452 2452
+1 -1
drivers/usb/gadget/function/f_uac1.c
··· 1512 1512 usb_put_function_instance(&opts->func_inst); 1513 1513 } 1514 1514 1515 - static struct configfs_item_operations f_uac1_item_ops = { 1515 + static const struct configfs_item_operations f_uac1_item_ops = { 1516 1516 .release = f_uac1_attr_release, 1517 1517 }; 1518 1518
+1 -1
drivers/usb/gadget/function/f_uac1_legacy.c
··· 812 812 usb_put_function_instance(&opts->func_inst); 813 813 } 814 814 815 - static struct configfs_item_operations f_uac1_item_ops = { 815 + static const struct configfs_item_operations f_uac1_item_ops = { 816 816 .release = f_uac1_attr_release, 817 817 }; 818 818
+1 -1
drivers/usb/gadget/function/f_uac2.c
··· 1874 1874 usb_put_function_instance(&opts->func_inst); 1875 1875 } 1876 1876 1877 - static struct configfs_item_operations f_uac2_item_ops = { 1877 + static const struct configfs_item_operations f_uac2_item_ops = { 1878 1878 .release = f_uac2_attr_release, 1879 1879 }; 1880 1880
+1 -1
drivers/usb/gadget/function/u_ether_configfs.h
··· 21 21 usb_put_function_instance(&opts->func_inst); \ 22 22 } \ 23 23 \ 24 - static struct configfs_item_operations _f_##_item_ops = { \ 24 + static const struct configfs_item_operations _f_##_item_ops = { \ 25 25 .release = _f_##_attr_release, \ 26 26 } 27 27
+18 -18
drivers/usb/gadget/function/uvc_configfs.c
··· 127 127 kfree(group); 128 128 } 129 129 130 - static struct configfs_item_operations uvcg_config_item_ops = { 130 + static const struct configfs_item_operations uvcg_config_item_ops = { 131 131 .release = uvcg_config_item_release, 132 132 }; 133 133 ··· 284 284 return &h->item; 285 285 } 286 286 287 - static struct configfs_group_operations uvcg_control_header_grp_ops = { 287 + static const struct configfs_group_operations uvcg_control_header_grp_ops = { 288 288 .make_item = uvcg_control_header_make, 289 289 }; 290 290 ··· 1232 1232 mutex_unlock(su_mutex); 1233 1233 } 1234 1234 1235 - static struct configfs_item_operations uvcg_extension_item_ops = { 1235 + static const struct configfs_item_operations uvcg_extension_item_ops = { 1236 1236 .release = uvcg_extension_release, 1237 1237 .allow_link = uvcg_extension_allow_link, 1238 1238 .drop_link = uvcg_extension_drop_link, ··· 1297 1297 return &xu->item; 1298 1298 } 1299 1299 1300 - static struct configfs_group_operations uvcg_extensions_grp_ops = { 1300 + static const struct configfs_group_operations uvcg_extensions_grp_ops = { 1301 1301 .make_item = uvcg_extension_make, 1302 1302 .drop_item = uvcg_extension_drop, 1303 1303 }; ··· 1413 1413 mutex_unlock(su_mutex); 1414 1414 } 1415 1415 1416 - static struct configfs_item_operations uvcg_control_class_item_ops = { 1416 + static const struct configfs_item_operations uvcg_control_class_item_ops = { 1417 1417 .release = uvcg_config_item_release, 1418 1418 .allow_link = uvcg_control_class_allow_link, 1419 1419 .drop_link = uvcg_control_class_drop_link, ··· 1663 1663 mutex_unlock(su_mutex); 1664 1664 } 1665 1665 1666 - static struct configfs_item_operations uvcg_format_item_operations = { 1666 + static const struct configfs_item_operations uvcg_format_item_operations = { 1667 1667 .release = uvcg_config_item_release, 1668 1668 .allow_link = uvcg_format_allow_link, 1669 1669 .drop_link = uvcg_format_drop_link, ··· 1839 1839 mutex_unlock(su_mutex); 1840 1840 } 1841 1841 1842 - static struct configfs_item_operations uvcg_streaming_header_item_ops = { 1842 + static const struct configfs_item_operations uvcg_streaming_header_item_ops = { 1843 1843 .release = uvcg_config_item_release, 1844 1844 .allow_link = uvcg_streaming_header_allow_link, 1845 1845 .drop_link = uvcg_streaming_header_drop_link, ··· 1913 1913 return &h->item; 1914 1914 } 1915 1915 1916 - static struct configfs_group_operations uvcg_streaming_header_grp_ops = { 1916 + static const struct configfs_group_operations uvcg_streaming_header_grp_ops = { 1917 1917 .make_item = uvcg_streaming_header_make, 1918 1918 }; 1919 1919 ··· 2260 2260 * streaming/uncompressed/<NAME> 2261 2261 */ 2262 2262 2263 - static struct configfs_group_operations uvcg_uncompressed_group_ops = { 2263 + static const struct configfs_group_operations uvcg_uncompressed_group_ops = { 2264 2264 .make_item = uvcg_frame_make, 2265 2265 .drop_item = uvcg_frame_drop, 2266 2266 }; ··· 2507 2507 return &h->fmt.group; 2508 2508 } 2509 2509 2510 - static struct configfs_group_operations uvcg_uncompressed_grp_ops = { 2510 + static const struct configfs_group_operations uvcg_uncompressed_grp_ops = { 2511 2511 .make_group = uvcg_uncompressed_make, 2512 2512 }; 2513 2513 ··· 2524 2524 * streaming/mjpeg/<NAME> 2525 2525 */ 2526 2526 2527 - static struct configfs_group_operations uvcg_mjpeg_group_ops = { 2527 + static const struct configfs_group_operations uvcg_mjpeg_group_ops = { 2528 2528 .make_item = uvcg_frame_make, 2529 2529 .drop_item = uvcg_frame_drop, 2530 2530 }; ··· 2697 2697 return &h->fmt.group; 2698 2698 } 2699 2699 2700 - static struct configfs_group_operations uvcg_mjpeg_grp_ops = { 2700 + static const struct configfs_group_operations uvcg_mjpeg_grp_ops = { 2701 2701 .make_group = uvcg_mjpeg_make, 2702 2702 }; 2703 2703 ··· 2714 2714 * streaming/framebased/<NAME> 2715 2715 */ 2716 2716 2717 - static struct configfs_group_operations uvcg_framebased_group_ops = { 2717 + static const struct configfs_group_operations uvcg_framebased_group_ops = { 2718 2718 .make_item = uvcg_frame_make, 2719 2719 .drop_item = uvcg_frame_drop, 2720 2720 }; ··· 2952 2952 return &h->fmt.group; 2953 2953 } 2954 2954 2955 - static struct configfs_group_operations uvcg_framebased_grp_ops = { 2955 + static const struct configfs_group_operations uvcg_framebased_grp_ops = { 2956 2956 .make_group = uvcg_framebased_make, 2957 2957 }; 2958 2958 ··· 3055 3055 kfree(color_match); 3056 3056 } 3057 3057 3058 - static struct configfs_item_operations uvcg_color_matching_item_ops = { 3058 + static const struct configfs_item_operations uvcg_color_matching_item_ops = { 3059 3059 .release = uvcg_color_matching_release, 3060 3060 }; 3061 3061 ··· 3088 3088 return &color_match->group; 3089 3089 } 3090 3090 3091 - static struct configfs_group_operations uvcg_color_matching_grp_group_ops = { 3091 + static const struct configfs_group_operations uvcg_color_matching_grp_group_ops = { 3092 3092 .make_group = uvcg_color_matching_make, 3093 3093 }; 3094 3094 ··· 3529 3529 mutex_unlock(su_mutex); 3530 3530 } 3531 3531 3532 - static struct configfs_item_operations uvcg_streaming_class_item_ops = { 3532 + static const struct configfs_item_operations uvcg_streaming_class_item_ops = { 3533 3533 .release = uvcg_config_item_release, 3534 3534 .allow_link = uvcg_streaming_class_allow_link, 3535 3535 .drop_link = uvcg_streaming_class_drop_link, ··· 3697 3697 mutex_unlock(&opts->lock); 3698 3698 } 3699 3699 3700 - static struct configfs_item_operations uvc_func_item_ops = { 3700 + static const struct configfs_item_operations uvc_func_item_ops = { 3701 3701 .release = uvc_func_item_release, 3702 3702 .allow_link = uvc_func_allow_link, 3703 3703 .drop_link = uvc_func_drop_link,
+2 -2
include/linux/usb/gadget_configfs.h
··· 30 30 CONFIGFS_ATTR(struct_name##_, _name) 31 31 32 32 #define USB_CONFIG_STRING_RW_OPS(struct_in) \ 33 - static struct configfs_item_operations struct_in##_langid_item_ops = { \ 33 + static const struct configfs_item_operations struct_in##_langid_item_ops = { \ 34 34 .release = struct_in##_attr_release, \ 35 35 }; \ 36 36 \ ··· 86 86 config_item_put(item); \ 87 87 } \ 88 88 \ 89 - static struct configfs_group_operations struct_in##_strings_ops = { \ 89 + static const struct configfs_group_operations struct_in##_strings_ops = { \ 90 90 .make_group = &struct_in##_strings_make, \ 91 91 .drop_item = &struct_in##_strings_drop, \ 92 92 }; \