Skip to contentSkip to conversation

ptp: ocp: fix start time alignment in ptp_ocp_signal_set

PATCH Applied Sagi Maimon 3 participants 3 messages Apr 15, 2025 – Apr 17, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ptp: ocp: fix start time alignment in ptp_ocp_signal_set

In ptp_ocp_signal_set, the start time for periodic signals is not aligned to the next period boundary. The current code rounds up the start time and divides by the period but fails to multiply back by the period, causing misaligned signal starts. Fix this by multiplying the rounded-up value by the period to ensure the start time is the closest next period.

Fixes 4bd46bb037f8e ("ptp: ocp: Use DIV64_U64_ROUND_UP for rounding.")

---
Addressed comments from Vadim Fedorenko:
- https://www.spinics.net/lists/netdev/msg1083572.html
Changes since version 1:
- Simplified multiplication in expression by removing unnecessary parentheses and using compound assignment operator, as suggested by the maintainer.

---
 drivers/ptp/ptp_ocp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/ptp/ptp_ocp.c +1 -0
index 7945c6be1f7c..faf6e027f89a 100644
@@ -2067,6 +2067,7 @@ ptp_ocp_signal_set(struct ptp_ocp *bp, int gen, struct ptp_ocp_signal *s)
 	if (!s->start) {
 		/* roundup() does not work on 32-bit systems */
 		s->start = DIV64_U64_ROUND_UP(start_ns, s->period);
+		s->start *= s->period;
 		s->start = ktime_add(s->start, s->phase);
 	}
 
Signature · 1 line
2.47.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 24 lines · Sagi Maimon

In ptp_ocp_signal_set, the start time for periodic signals is not aligned to the next period boundary. The current code rounds up the start time and divides by the period but fails to multiply back by the period, causing misaligned signal starts. Fix this by multiplying the rounded-up value by the period to ensure the start time is the closest next period.

Fixes 4bd46bb037f8e ("ptp: ocp: Use DIV64_U64_ROUND_UP for rounding.")

---
Addressed comments from Vadim Fedorenko:
- https://www.spinics.net/lists/netdev/msg1083572.html
Changes since version 1:
- Simplified multiplication in expression by removing unnecessary parentheses and using compound assignment operator, as suggested by the maintainer.

---
  drivers/ptp/ptp_ocp.c | 1 +
  1 file changed, 1 insertion(+)
drivers/ptp/ptp_ocp.c +0 -0
index 7945c6be1f7c..faf6e027f89a 100644

drivers/ptp/ptp_ocp.c ptp_ocp_signal_set(struct ptp_ocp *bp, int gen, struct ptp_ocp_signal *s) · line 2073

Quoted 7 lines
drivers/ptp/ptp_ocp.c +1 -0
@@ -2067,6 +2067,7 @@ ptp_ocp_signal_set(struct ptp_ocp *bp, int gen, struct ptp_ocp_signal *s)
  	if (!s->start) {
  		/* roundup() does not work on 32-bit systems */
  		s->start = DIV64_U64_ROUND_UP(start_ns, s->period);
+		s->start *= s->period;
  		s->start = ktime_add(s->start, s->phase);
  	}
 
#2 lore raw
In reply to Sagi Maimon
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 15 Apr 2025 08:31:31 +0300 you wrote:

In ptp_ocp_signal_set, the start time for periodic signals is not aligned to the next period boundary. The current code rounds up the start time and divides by the period but fails to multiply back by the period, causing misaligned signal starts. Fix this by multiplying the rounded-up value by the period to ensure the start time is the closest next period.

[...]

Here is the summary with links:
- [v2] ptp: ocp: fix start time alignment in ptp_ocp_signal_set

    https://git.kernel.org/netdev/net/c/2a5970d5aaff

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html