Commit 6d351515 authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

fsm.c: bugfix, exposed by link down/up in wr-switch

Commit d2b2c636 introduced a caching of the current state structure.
The "current" structure, as long as not null, is considered valid.
arch-wrs, just sets ppi->state to initializing on link-up, without
clearing the cached pointer, so fsm.c was using the old pointer,
resulting in use of closed file descriptors, as no init was performed.

This doesn't apply to change from withing the states themselves, as
fsm.c manages the state change.

As a side effect, now that we check the state numberm there's no need
to zero the pointer on state leave. (And while a it another trivial detail...).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 5d9c5024
...@@ -65,20 +65,19 @@ static void pp_diag_fsm(struct pp_instance *ppi, char *name, int sequence, ...@@ -65,20 +65,19 @@ static void pp_diag_fsm(struct pp_instance *ppi, char *name, int sequence,
static struct pp_state_table_item * static struct pp_state_table_item *
get_current_state_table_item(struct pp_instance *ppi) get_current_state_table_item(struct pp_instance *ppi)
{ {
struct pp_state_table_item *ip; struct pp_state_table_item *ip = ppi->current_state_item;;
struct pp_state_table_item *out = NULL;
/* Avoid searching if we already know where we are */ /* Avoid searching if we already know where we are */
if (ppi->current_state_item) if (ip && ip->state == ppi->state)
return ppi->current_state_item; return ip;
/* a linear search is affordable up to a few dozen items */ /* a linear search is affordable up to a few dozen items */
for (ip = pp_state_table; ip->state != PPS_END_OF_TABLE && !out; ip++) for (ip = pp_state_table; ip->state != PPS_END_OF_TABLE; ip++)
if (ip->state == ppi->state) { if (ip->state == ppi->state) {
out = ip;
ppi->current_state_item = ip; ppi->current_state_item = ip;
return ip;
} }
return out; return NULL;
} }
/* /*
...@@ -91,7 +90,6 @@ static int leave_current_state(struct pp_instance *ppi) ...@@ -91,7 +90,6 @@ static int leave_current_state(struct pp_instance *ppi)
pp_timeout_setall(ppi); pp_timeout_setall(ppi);
ppi->flags &= ~PPI_FLAGS_WAITING; ppi->flags &= ~PPI_FLAGS_WAITING;
pp_diag_fsm(ppi, ppi->current_state_item->name, STATE_LEAVE, 0); pp_diag_fsm(ppi, ppi->current_state_item->name, STATE_LEAVE, 0);
ppi->current_state_item = NULL;
/* next_delay unused: go to new state now */ /* next_delay unused: go to new state now */
return 0; return 0;
} }
......
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