Skip to content

Commit

Permalink
Change a misleading fault handling function signature.
Browse files Browse the repository at this point in the history
Looking at the fault logic in port_dispatch(), you might think that
the function, fault_interval(), checks whether a fault is active, but
you would be wrong, since that function always returns zero.

This patch removes the superfluous input error checking inside of
fault_interval() and changes the return type to void, making the
actual behavior explicit.  Dropping the input check is safe because
that function has exactly two callers, both of whom always provide
valid inputs.

Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Jan 8, 2017
1 parent 10d4e7f commit 80a28a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
15 changes: 5 additions & 10 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,11 @@ enum fault_type last_fault_type(struct port *port)
return port->last_fault_type;
}

int fault_interval(struct port *port, enum fault_type ft,
struct fault_interval *i)
void fault_interval(struct port *port, enum fault_type ft,
struct fault_interval *i)
{
if (!port || !i)
return -EINVAL;
if (ft < 0 || ft >= FT_CNT)
return -EINVAL;
i->type = port->flt_interval_pertype[ft].type;
i->val = port->flt_interval_pertype[ft].val;
return 0;
}

int port_fault_fd(struct port *port)
Expand Down Expand Up @@ -2147,9 +2142,9 @@ int port_dispatch(struct port *p, enum fsm_event event, int mdiff)
}
next = p->state_machine(p->state, event, mdiff);

if (!fault_interval(p, last_fault_type(p), &i) &&
((i.val == FRI_ASAP && i.type == FTMO_LOG2_SECONDS) ||
(i.val == 0 && i.type == FTMO_LINEAR_SECONDS)))
fault_interval(p, last_fault_type(p), &i);
if ((i.val == FRI_ASAP && i.type == FTMO_LOG2_SECONDS) ||
(i.val == 0 && i.type == FTMO_LINEAR_SECONDS))
fri_asap = 1;
if (PS_INITIALIZING == next || (PS_FAULTY == next && fri_asap)) {
/*
Expand Down
5 changes: 2 additions & 3 deletions port.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,8 @@ enum fault_type last_fault_type(struct port *port);
* @param port A port instance.
* @param ft Fault type.
* @param i Pointer to the struct which will be filled in.
* @return Zero on success, non-zero otherwise.
*/
int fault_interval(struct port *port, enum fault_type ft,
struct fault_interval *i);
void fault_interval(struct port *port, enum fault_type ft,
struct fault_interval *i);

#endif

0 comments on commit 80a28a9

Please sign in to comment.