Commit fa17b6c7 authored by Davide Ciminaghi's avatar Davide Ciminaghi Committed by Alessandro Rubini

fsm: reduce indentation level

parent 07e328e3
......@@ -62,6 +62,19 @@ static void pp_diag_fsm(struct pp_instance *ppi, char *name, int sequence,
name, ppi->next_state);
}
static struct pp_state_table_item *
get_current_state_table_item(struct pp_instance *ppi)
{
struct pp_state_table_item *ip;
struct pp_state_table_item *out = NULL;
/* a linear search is affordable up to a few dozen items */
for (ip = pp_state_table; ip->state != PPS_END_OF_TABLE && !out; ip++)
if (ip->state == ppi->state)
out = ip;
return out;
}
/*
* This is the state machine code. i.e. the extension-independent
* function that runs the machine. Errors are managed and reported
......@@ -103,10 +116,12 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
state = ppi->state;
/* a linear search is affordable up to a few dozen items */
for (ip = pp_state_table; ip->state != PPS_END_OF_TABLE; ip++) {
if (ip->state != state)
continue;
ip = get_current_state_table_item(ppi);
if (!ip) {
pp_printf("fsm: Unknown state for port %s\n", ppi->port_name);
return 10000; /* No way out. Repeat message every 10s */
}
/* found: handle this state */
ppi->next_state = state;
ppi->next_delay = 0;
......@@ -129,8 +144,4 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
ppi->is_new_state = 0;
pp_diag_fsm(ppi, ip->name, STATE_LOOP, 0);
return ppi->next_delay;
}
/* Unknwon state, can't happen */
pp_printf("fsm: Unknown state for port %s\n", ppi->port_name);
return 10000; /* No way out. Repeat message every 10s */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment