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

llc: Constify struct llc_sap_state_trans

'struct llc_sap_state_trans' are not modified in this driver.

Constifying this structure moves some data to a read-only section, so
increase overall security.

On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
339 456 24 819 333 net/llc/llc_s_st.o

After:
=====
text data bss dec hex filename
683 144 0 827 33b net/llc/llc_s_st.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/9d17587639195ee94b74ff06a11ef97d1833ee52.1720973710.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Christophe JAILLET and committed by
Jakub Kicinski
0970bf67 70de41ef

+21 -21
+2 -2
include/net/llc_s_st.h
··· 29 29 }; 30 30 31 31 struct llc_sap_state { 32 - u8 curr_state; 33 - struct llc_sap_state_trans **transitions; 32 + u8 curr_state; 33 + const struct llc_sap_state_trans **transitions; 34 34 }; 35 35 36 36 /* only access to SAP state table */
+13 -13
net/llc/llc_s_st.c
··· 24 24 * last entry for this state 25 25 * all members are zeros, .bss zeroes it 26 26 */ 27 - static struct llc_sap_state_trans llc_sap_state_trans_end; 27 + static const struct llc_sap_state_trans llc_sap_state_trans_end; 28 28 29 29 /* state LLC_SAP_STATE_INACTIVE transition for 30 30 * LLC_SAP_EV_ACTIVATION_REQ event ··· 34 34 [1] = NULL, 35 35 }; 36 36 37 - static struct llc_sap_state_trans llc_sap_inactive_state_trans_1 = { 37 + static const struct llc_sap_state_trans llc_sap_inactive_state_trans_1 = { 38 38 .ev = llc_sap_ev_activation_req, 39 39 .next_state = LLC_SAP_STATE_ACTIVE, 40 40 .ev_actions = llc_sap_inactive_state_actions_1, 41 41 }; 42 42 43 43 /* array of pointers; one to each transition */ 44 - static struct llc_sap_state_trans *llc_sap_inactive_state_transitions[] = { 44 + static const struct llc_sap_state_trans *llc_sap_inactive_state_transitions[] = { 45 45 [0] = &llc_sap_inactive_state_trans_1, 46 46 [1] = &llc_sap_state_trans_end, 47 47 }; ··· 52 52 [1] = NULL, 53 53 }; 54 54 55 - static struct llc_sap_state_trans llc_sap_active_state_trans_1 = { 55 + static const struct llc_sap_state_trans llc_sap_active_state_trans_1 = { 56 56 .ev = llc_sap_ev_rx_ui, 57 57 .next_state = LLC_SAP_STATE_ACTIVE, 58 58 .ev_actions = llc_sap_active_state_actions_1, ··· 64 64 [1] = NULL, 65 65 }; 66 66 67 - static struct llc_sap_state_trans llc_sap_active_state_trans_2 = { 67 + static const struct llc_sap_state_trans llc_sap_active_state_trans_2 = { 68 68 .ev = llc_sap_ev_unitdata_req, 69 69 .next_state = LLC_SAP_STATE_ACTIVE, 70 70 .ev_actions = llc_sap_active_state_actions_2, ··· 76 76 [1] = NULL, 77 77 }; 78 78 79 - static struct llc_sap_state_trans llc_sap_active_state_trans_3 = { 79 + static const struct llc_sap_state_trans llc_sap_active_state_trans_3 = { 80 80 .ev = llc_sap_ev_xid_req, 81 81 .next_state = LLC_SAP_STATE_ACTIVE, 82 82 .ev_actions = llc_sap_active_state_actions_3, ··· 88 88 [1] = NULL, 89 89 }; 90 90 91 - static struct llc_sap_state_trans llc_sap_active_state_trans_4 = { 91 + static const struct llc_sap_state_trans llc_sap_active_state_trans_4 = { 92 92 .ev = llc_sap_ev_rx_xid_c, 93 93 .next_state = LLC_SAP_STATE_ACTIVE, 94 94 .ev_actions = llc_sap_active_state_actions_4, ··· 100 100 [1] = NULL, 101 101 }; 102 102 103 - static struct llc_sap_state_trans llc_sap_active_state_trans_5 = { 103 + static const struct llc_sap_state_trans llc_sap_active_state_trans_5 = { 104 104 .ev = llc_sap_ev_rx_xid_r, 105 105 .next_state = LLC_SAP_STATE_ACTIVE, 106 106 .ev_actions = llc_sap_active_state_actions_5, ··· 112 112 [1] = NULL, 113 113 }; 114 114 115 - static struct llc_sap_state_trans llc_sap_active_state_trans_6 = { 115 + static const struct llc_sap_state_trans llc_sap_active_state_trans_6 = { 116 116 .ev = llc_sap_ev_test_req, 117 117 .next_state = LLC_SAP_STATE_ACTIVE, 118 118 .ev_actions = llc_sap_active_state_actions_6, ··· 124 124 [1] = NULL, 125 125 }; 126 126 127 - static struct llc_sap_state_trans llc_sap_active_state_trans_7 = { 127 + static const struct llc_sap_state_trans llc_sap_active_state_trans_7 = { 128 128 .ev = llc_sap_ev_rx_test_c, 129 129 .next_state = LLC_SAP_STATE_ACTIVE, 130 130 .ev_actions = llc_sap_active_state_actions_7 ··· 136 136 [1] = NULL, 137 137 }; 138 138 139 - static struct llc_sap_state_trans llc_sap_active_state_trans_8 = { 139 + static const struct llc_sap_state_trans llc_sap_active_state_trans_8 = { 140 140 .ev = llc_sap_ev_rx_test_r, 141 141 .next_state = LLC_SAP_STATE_ACTIVE, 142 142 .ev_actions = llc_sap_active_state_actions_8, ··· 150 150 [1] = NULL, 151 151 }; 152 152 153 - static struct llc_sap_state_trans llc_sap_active_state_trans_9 = { 153 + static const struct llc_sap_state_trans llc_sap_active_state_trans_9 = { 154 154 .ev = llc_sap_ev_deactivation_req, 155 155 .next_state = LLC_SAP_STATE_INACTIVE, 156 156 .ev_actions = llc_sap_active_state_actions_9 157 157 }; 158 158 159 159 /* array of pointers; one to each transition */ 160 - static struct llc_sap_state_trans *llc_sap_active_state_transitions[] = { 160 + static const struct llc_sap_state_trans *llc_sap_active_state_transitions[] = { 161 161 [0] = &llc_sap_active_state_trans_2, 162 162 [1] = &llc_sap_active_state_trans_1, 163 163 [2] = &llc_sap_active_state_trans_3,
+6 -6
net/llc/llc_sap.c
··· 114 114 * Returns the pointer to found transition on success or %NULL for 115 115 * failure. 116 116 */ 117 - static struct llc_sap_state_trans *llc_find_sap_trans(struct llc_sap *sap, 118 - struct sk_buff *skb) 117 + static const struct llc_sap_state_trans *llc_find_sap_trans(struct llc_sap *sap, 118 + struct sk_buff *skb) 119 119 { 120 120 int i = 0; 121 - struct llc_sap_state_trans *rc = NULL; 122 - struct llc_sap_state_trans **next_trans; 121 + const struct llc_sap_state_trans *rc = NULL; 122 + const struct llc_sap_state_trans **next_trans; 123 123 struct llc_sap_state *curr_state = &llc_sap_state_table[sap->state - 1]; 124 124 /* 125 125 * Search thru events for this state until list exhausted or until ··· 143 143 * Returns 0 for success and 1 for failure of at least one action. 144 144 */ 145 145 static int llc_exec_sap_trans_actions(struct llc_sap *sap, 146 - struct llc_sap_state_trans *trans, 146 + const struct llc_sap_state_trans *trans, 147 147 struct sk_buff *skb) 148 148 { 149 149 int rc = 0; ··· 166 166 */ 167 167 static int llc_sap_next_state(struct llc_sap *sap, struct sk_buff *skb) 168 168 { 169 + const struct llc_sap_state_trans *trans; 169 170 int rc = 1; 170 - struct llc_sap_state_trans *trans; 171 171 172 172 if (sap->state > LLC_NR_SAP_STATES) 173 173 goto out;