Time values are compared using an inequality test in mmedian.c
Generalise tmv_eq() to tmv_cmp() (by analogy with memcmp()) and
replace existing uses of tmv_eq().

Signed-off-by: Michael Brown <mbr...@fensystems.co.uk>
---
 clock.c   | 2 +-
 mmedian.c | 3 ++-
 port.c    | 2 +-
 tmv.h     | 4 ++--
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/clock.c b/clock.c
index e9e5d74..92adea8 100644
--- a/clock.c
+++ b/clock.c
@@ -590,7 +590,7 @@ static enum servo_state clock_no_adjust(struct clock *c, 
tmv_t ingress,
        if (f->count < f->max_count) {
                return state;
        }
-       if (tmv_eq(ingress, f->ingress1)) {
+       if (tmv_cmp(ingress, f->ingress1) == 0) {
                pr_warning("bad timestamps in rate ratio calculation");
                return state;
        }
diff --git a/mmedian.c b/mmedian.c
index 1d15789..2383467 100644
--- a/mmedian.c
+++ b/mmedian.c
@@ -60,7 +60,8 @@ static tmv_t mmedian_sample(struct filter *filter, tmv_t 
sample)
 
        /* Insert index of the new value to order. */
        for (i = m->cnt - 1; i > 0; i--) {
-               if (m->samples[m->order[i - 1]] <= m->samples[m->index])
+               if (tmv_cmp(m->samples[m->order[i - 1]],
+                           m->samples[m->index]) <= 0)
                        break;
                m->order[i] = m->order[i - 1];
        }
diff --git a/port.c b/port.c
index 6f91320..ee09b5c 100644
--- a/port.c
+++ b/port.c
@@ -938,7 +938,7 @@ static void port_nrate_calculate(struct port *p, tmv_t 
origin, tmv_t ingress)
        if (n->count < n->max_count) {
                return;
        }
-       if (tmv_eq(ingress, n->ingress1)) {
+       if (tmv_cmp(ingress, n->ingress1) == 0) {
                pr_warning("bad timestamps in nrate calculation");
                return;
        }
diff --git a/tmv.h b/tmv.h
index 30b41ee..5717846 100644
--- a/tmv.h
+++ b/tmv.h
@@ -51,9 +51,9 @@ static inline tmv_t tmv_div(tmv_t a, int divisor)
        return a / divisor;
 }
 
-static inline int tmv_eq(tmv_t a, tmv_t b)
+static inline int tmv_cmp(tmv_t a, tmv_t b)
 {
-       return a == b ? 1 : 0;
+       return a == b ? 0 : a > b ? +1 : -1;
 }
 
 static inline int tmv_is_zero(tmv_t x)
-- 
2.9.5


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to