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

llc2: Collapse remainder of state machine into simple if-else if-statement

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ben Hutchings and committed by
David S. Miller
12ebc8b9 da318880

+4 -87
+4 -87
net/llc/llc_station.c
··· 25 25 #include <net/llc_s_st.h> 26 26 #include <net/llc_pdu.h> 27 27 28 - typedef int (*llc_station_ev_t)(struct sk_buff *skb); 29 - 30 - typedef int (*llc_station_action_t)(struct sk_buff *skb); 31 - 32 - /* Station component state table structure */ 33 - struct llc_station_state_trans { 34 - llc_station_ev_t ev; 35 - llc_station_action_t *ev_actions; 36 - }; 37 - 38 28 static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb) 39 29 { 40 30 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); ··· 99 109 goto out; 100 110 } 101 111 102 - /* state transition for LLC_STATION_EV_RX_NULL_DSAP_XID_C event */ 103 - static llc_station_action_t llc_stat_up_state_actions_2[] = { 104 - llc_station_ac_send_xid_r, 105 - NULL, 106 - }; 107 - 108 - static struct llc_station_state_trans llc_stat_up_state_trans_2 = { 109 - .ev = llc_stat_ev_rx_null_dsap_xid_c, 110 - .ev_actions = llc_stat_up_state_actions_2, 111 - }; 112 - 113 - /* state transition for LLC_STATION_EV_RX_NULL_DSAP_TEST_C event */ 114 - static llc_station_action_t llc_stat_up_state_actions_3[] = { 115 - llc_station_ac_send_test_r, 116 - NULL, 117 - }; 118 - 119 - static struct llc_station_state_trans llc_stat_up_state_trans_3 = { 120 - .ev = llc_stat_ev_rx_null_dsap_test_c, 121 - .ev_actions = llc_stat_up_state_actions_3, 122 - }; 123 - 124 - /* array of pointers; one to each transition */ 125 - static struct llc_station_state_trans *llc_stat_up_state_trans [] = { 126 - &llc_stat_up_state_trans_2, 127 - &llc_stat_up_state_trans_3, 128 - NULL, 129 - }; 130 - 131 - /** 132 - * llc_exec_station_trans_actions - executes actions for transition 133 - * @trans: Address of the transition 134 - * @skb: Address of the event that caused the transition 135 - * 136 - * Executes actions of a transition of the station state machine. Returns 137 - * 0 if all actions complete successfully, nonzero otherwise. 138 - */ 139 - static u16 llc_exec_station_trans_actions(struct llc_station_state_trans *trans, 140 - struct sk_buff *skb) 141 - { 142 - u16 rc = 0; 143 - llc_station_action_t *next_action = trans->ev_actions; 144 - 145 - for (; next_action && *next_action; next_action++) 146 - if ((*next_action)(skb)) 147 - rc = 1; 148 - return rc; 149 - } 150 - 151 - /** 152 - * llc_find_station_trans - finds transition for this event 153 - * @skb: Address of the event 154 - * 155 - * Search thru events of the current state of the station until list 156 - * exhausted or it's obvious that the event is not valid for the current 157 - * state. Returns the address of the transition if cound, %NULL otherwise. 158 - */ 159 - static struct llc_station_state_trans * 160 - llc_find_station_trans(struct sk_buff *skb) 161 - { 162 - int i = 0; 163 - struct llc_station_state_trans *rc = NULL; 164 - struct llc_station_state_trans **next_trans; 165 - 166 - for (next_trans = llc_stat_up_state_trans; next_trans[i]; i++) 167 - if (!next_trans[i]->ev(skb)) { 168 - rc = next_trans[i]; 169 - break; 170 - } 171 - return rc; 172 - } 173 - 174 112 /** 175 113 * llc_station_rcv - send received pdu to the station state machine 176 114 * @skb: received frame. ··· 107 189 */ 108 190 static void llc_station_rcv(struct sk_buff *skb) 109 191 { 110 - struct llc_station_state_trans *trans; 111 - 112 - trans = llc_find_station_trans(skb); 113 - if (trans) 114 - llc_exec_station_trans_actions(trans, skb); 192 + if (llc_stat_ev_rx_null_dsap_xid_c(skb)) 193 + llc_station_ac_send_xid_r(skb); 194 + else if (llc_stat_ev_rx_null_dsap_test_c(skb)) 195 + llc_station_ac_send_test_r(skb); 115 196 kfree_skb(skb); 116 197 } 117 198