]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ptp: ocp: have adjtime handle negative delta_ns correctly
authorJonathan Lemon <jonathan.lemon@gmail.com>
Fri, 13 May 2022 22:52:31 +0000 (15:52 -0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 16 May 2022 20:07:46 +0000 (13:07 -0700)
delta_ns is a s64, but it was being passed ptp_ocp_adjtime_coarse
as an u64.  Also, it turns out that timespec64_add_ns() only handles
positive values, so perform the math with set_normalized_timespec().

Fixes: d6c5da8943dc ("ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments")
Suggested-by: Vadim Fedorenko <vfedorenko@novek.ru>
Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Acked-by: Vadim Fedorenko <vfedorenko@novek.ru>
Link: https://lore.kernel.org/r/20220513225231.1412-1-jonathan.lemon@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/ptp/ptp_ocp.c

index dd45471f678083358a7b0b6c34770c1d04c47409..36c0e188216b1880510ba76140bf2b362e9b6f1d 100644 (file)
@@ -841,7 +841,7 @@ __ptp_ocp_adjtime_locked(struct ptp_ocp *bp, u32 adj_val)
 }
 
 static void
-ptp_ocp_adjtime_coarse(struct ptp_ocp *bp, u64 delta_ns)
+ptp_ocp_adjtime_coarse(struct ptp_ocp *bp, s64 delta_ns)
 {
        struct timespec64 ts;
        unsigned long flags;
@@ -850,7 +850,8 @@ ptp_ocp_adjtime_coarse(struct ptp_ocp *bp, u64 delta_ns)
        spin_lock_irqsave(&bp->lock, flags);
        err = __ptp_ocp_gettime_locked(bp, &ts, NULL);
        if (likely(!err)) {
-               timespec64_add_ns(&ts, delta_ns);
+               set_normalized_timespec64(&ts, ts.tv_sec,
+                                         ts.tv_nsec + delta_ns);
                __ptp_ocp_settime_locked(bp, &ts);
        }
        spin_unlock_irqrestore(&bp->lock, flags);