Guard against divide by zero.
If a buggy driver or hardware delivers bogus time stamps, then we might crash with a divide by zero exception. Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
35170cf6e4
commit
8f5bd0edda
4
clock.c
4
clock.c
|
@ -209,6 +209,10 @@ static enum servo_state clock_no_adjust(struct clock *c)
|
||||||
if (f->count < f->max_count) {
|
if (f->count < f->max_count) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
if (tmv_eq(c->t2, f->ingress1)) {
|
||||||
|
pr_warning("bad timestamps in rate ratio calculation");
|
||||||
|
return state;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* origin2 = c->t1 (+c->path_delay) + c->c1 + c->c2;
|
* origin2 = c->t1 (+c->path_delay) + c->c1 + c->c2;
|
||||||
*/
|
*/
|
||||||
|
|
4
port.c
4
port.c
|
@ -407,6 +407,10 @@ static void port_nrate_calculate(struct port *p, tmv_t t3, tmv_t t4, tmv_t c)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
origin2 = tmv_add(t3, c);
|
origin2 = tmv_add(t3, c);
|
||||||
|
if (tmv_eq(t4, n->ingress1)) {
|
||||||
|
pr_warning("bad timestamps in nrate calculation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
n->ratio =
|
n->ratio =
|
||||||
tmv_dbl(tmv_sub(origin2, n->origin1)) /
|
tmv_dbl(tmv_sub(origin2, n->origin1)) /
|
||||||
tmv_dbl(tmv_sub(t4, n->ingress1));
|
tmv_dbl(tmv_sub(t4, n->ingress1));
|
||||||
|
|
5
tmv.h
5
tmv.h
|
@ -51,6 +51,11 @@ static inline tmv_t tmv_div(tmv_t a, int divisor)
|
||||||
return a / divisor;
|
return a / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int tmv_eq(tmv_t a, tmv_t b)
|
||||||
|
{
|
||||||
|
return a == b ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int tmv_is_zero(tmv_t x)
|
static inline int tmv_is_zero(tmv_t x)
|
||||||
{
|
{
|
||||||
return x == ((tmv_t) 0) ? 1 : 0;
|
return x == ((tmv_t) 0) ? 1 : 0;
|
||||||
|
|
Loading…
Reference in New Issue