From 80a28a9dc322f28b991effc44ec1c5362a598281 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Tue, 3 Jan 2017 20:55:33 +0100 Subject: [PATCH] Change a misleading fault handling function signature. 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 --- port.c | 15 +++++---------- port.h | 5 ++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/port.c b/port.c index afe0057..6c9aa72 100644 --- a/port.c +++ b/port.c @@ -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) @@ -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)) { /* diff --git a/port.h b/port.h index 19dec4a..d2e0865 100644 --- a/port.h +++ b/port.h @@ -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