ptp: ocp: have adjtime handle negative delta_ns correctly
PATCH RESEND 1/1 ptp: ocp: have adjtime handle negative delta_ns correctly
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 the math needs to be updated.
Fix by passing in the correct signed value, then adding to a nanosecond version of the timespec.
---
Resend to fix misquoted Fixes: tag
--- drivers/ptp/ptp_ocp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/ptp/ptp_ocp.c +4 -2
@@ -841,16 +841,18 @@ __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;int err; +s64 ns;spin_lock_irqsave (&bp->lock, flags); err =__ptp_ocp_gettime_locked (bp, &ts,NULL );if (likely (!err)) { -timespec64_add_ns (&ts, delta_ns); + ns =timespec64_to_ns (&ts) + delta_ns; + ts =ns_to_timespec64 (ns);__ptp_ocp_settime_locked (bp, &ts); }spin_unlock_irqrestore (&bp->lock, flags);
Signature · 1 line
2.31.1
PATCH RESEND 1/1 ptp: ocp: Use DIV64_U64_ROUND_UP for rounding.
The initial code used roundup() to round the starting time to a multiple of a period. This generated an error on 32-bit systems, so was replaced with DIV_ROUND_UP_ULL().
However, this truncates to 32-bits on a 64-bit system. Replace with DIV64_U64_ROUND_UP() instead.
---
Resend to fix misquoted Fixes: tag
--- drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
@@ -1557,7 +1557,7 @@ ptp_ocp_signal_set(struct ptp_ocp *bp, int gen, struct ptp_ocp_signal *s) start_ns =ktime_set (ts.tv_sec, ts.tv_nsec) +NSEC_PER_MSEC ;if (!s->start) {/* roundup() does not work on 32-bit systems */ - s->start =DIV_ROUND_UP_ULL (start_ns, s->period); + s->start =DIV64_U64_ROUND_UP (start_ns, s->period); s->start =ktime_add (s->start, s->phase); }
Signature · 1 line
2.31.1
Re: [PATCH net RESEND] ptp: ocp: Use DIV64_U64_ROUND_UP for rounding.
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Fri, 6 May 2022 15:37:39 -0700 you wrote:
The initial code used
roundup()to round the starting time to a multiple of a period. This generated an error on 32-bit systems, so was replaced withDIV_ROUND_UP_ULL().However, this truncates to 32-bits on a 64-bit system. Replace with
DIV64_U64_ROUND_UP()instead.[...]
Here is the summary with links:
- [net,RESEND] ptp: ocp: Use DIV64_U64_ROUND_UP for rounding.
https://git.kernel.org/netdev/net/c/4bd46bb037f8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html