Skip to content

Commit 12ebc8b

Browse files
bwhacksdavem330
authored andcommitted
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>
1 parent da31888 commit 12ebc8b

1 file changed

Lines changed: 4 additions & 87 deletions

File tree

‎net/llc/llc_station.c‎

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525
#include <net/llc_s_st.h>
2626
#include <net/llc_pdu.h>
2727

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-
3828
static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb)
3929
{
4030
struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
@@ -109,78 +99,6 @@ static int llc_station_ac_send_test_r(struct sk_buff *skb)
10999
goto out;
110100
}
111101

112-
/* state transition for LLC_STATION_EV_RX_NULL_DSAP_XID_C event */
113-
static llc_station_action_t llc_stat_up_state_actions_2[] = {
114-
llc_station_ac_send_xid_r,
115-
NULL,
116-
};
117-
118-
static struct llc_station_state_trans llc_stat_up_state_trans_2 = {
119-
.ev = llc_stat_ev_rx_null_dsap_xid_c,
120-
.ev_actions = llc_stat_up_state_actions_2,
121-
};
122-
123-
/* state transition for LLC_STATION_EV_RX_NULL_DSAP_TEST_C event */
124-
static llc_station_action_t llc_stat_up_state_actions_3[] = {
125-
llc_station_ac_send_test_r,
126-
NULL,
127-
};
128-
129-
static struct llc_station_state_trans llc_stat_up_state_trans_3 = {
130-
.ev = llc_stat_ev_rx_null_dsap_test_c,
131-
.ev_actions = llc_stat_up_state_actions_3,
132-
};
133-
134-
/* array of pointers; one to each transition */
135-
static struct llc_station_state_trans *llc_stat_up_state_trans [] = {
136-
&llc_stat_up_state_trans_2,
137-
&llc_stat_up_state_trans_3,
138-
NULL,
139-
};
140-
141-
/**
142-
* llc_exec_station_trans_actions - executes actions for transition
143-
* @trans: Address of the transition
144-
* @skb: Address of the event that caused the transition
145-
*
146-
* Executes actions of a transition of the station state machine. Returns
147-
* 0 if all actions complete successfully, nonzero otherwise.
148-
*/
149-
static u16 llc_exec_station_trans_actions(struct llc_station_state_trans *trans,
150-
struct sk_buff *skb)
151-
{
152-
u16 rc = 0;
153-
llc_station_action_t *next_action = trans->ev_actions;
154-
155-
for (; next_action && *next_action; next_action++)
156-
if ((*next_action)(skb))
157-
rc = 1;
158-
return rc;
159-
}
160-
161-
/**
162-
* llc_find_station_trans - finds transition for this event
163-
* @skb: Address of the event
164-
*
165-
* Search thru events of the current state of the station until list
166-
* exhausted or it's obvious that the event is not valid for the current
167-
* state. Returns the address of the transition if cound, %NULL otherwise.
168-
*/
169-
static struct llc_station_state_trans *
170-
llc_find_station_trans(struct sk_buff *skb)
171-
{
172-
int i = 0;
173-
struct llc_station_state_trans *rc = NULL;
174-
struct llc_station_state_trans **next_trans;
175-
176-
for (next_trans = llc_stat_up_state_trans; next_trans[i]; i++)
177-
if (!next_trans[i]->ev(skb)) {
178-
rc = next_trans[i];
179-
break;
180-
}
181-
return rc;
182-
}
183-
184102
/**
185103
* llc_station_rcv - send received pdu to the station state machine
186104
* @skb: received frame.
@@ -189,11 +107,10 @@ static struct llc_station_state_trans *
189107
*/
190108
static void llc_station_rcv(struct sk_buff *skb)
191109
{
192-
struct llc_station_state_trans *trans;
193-
194-
trans = llc_find_station_trans(skb);
195-
if (trans)
196-
llc_exec_station_trans_actions(trans, skb);
110+
if (llc_stat_ev_rx_null_dsap_xid_c(skb))
111+
llc_station_ac_send_xid_r(skb);
112+
else if (llc_stat_ev_rx_null_dsap_test_c(skb))
113+
llc_station_ac_send_test_r(skb);
197114
kfree_skb(skb);
198115
}
199116

0 commit comments

Comments
 (0)