netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ptp: ocp: fix start time alignment in ptp_ocp_signal_set
@ 2025-04-15  5:31 Sagi Maimon
  2025-04-15  7:51 ` Vadim Fedorenko
  2025-04-17  1:31 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Sagi Maimon @ 2025-04-15  5:31 UTC (permalink / raw)
  To: jonathan.lemon, vadim.fedorenko, richardcochran, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: linux-kernel, netdev, 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.")
Signed-off-by: Sagi Maimon <maimon.sagi@gmail.com>
---
 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(+)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 7945c6be1f7c..faf6e027f89a 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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.47.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ptp: ocp: fix start time alignment in ptp_ocp_signal_set
  2025-04-15  5:31 [PATCH v2] ptp: ocp: fix start time alignment in ptp_ocp_signal_set Sagi Maimon
@ 2025-04-15  7:51 ` Vadim Fedorenko
  2025-04-17  1:31 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Vadim Fedorenko @ 2025-04-15  7:51 UTC (permalink / raw)
  To: Sagi Maimon, jonathan.lemon, richardcochran, andrew+netdev, davem,
	edumazet, kuba, pabeni
  Cc: linux-kernel, netdev

On 15/04/2025 06:31, Sagi Maimon 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.
> 
> Fixes: 4bd46bb037f8e ("ptp: ocp: Use DIV64_U64_ROUND_UP for rounding.")
> Signed-off-by: Sagi Maimon <maimon.sagi@gmail.com>
> ---
>   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(+)
> 
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 7945c6be1f7c..faf6e027f89a 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -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);
>   	}
>   
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ptp: ocp: fix start time alignment in ptp_ocp_signal_set
  2025-04-15  5:31 [PATCH v2] ptp: ocp: fix start time alignment in ptp_ocp_signal_set Sagi Maimon
  2025-04-15  7:51 ` Vadim Fedorenko
@ 2025-04-17  1:31 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-17  1:31 UTC (permalink / raw)
  To: Sagi Maimon
  Cc: jonathan.lemon, vadim.fedorenko, richardcochran, andrew+netdev,
	davem, edumazet, kuba, pabeni, linux-kernel, netdev

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-17  1:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15  5:31 [PATCH v2] ptp: ocp: fix start time alignment in ptp_ocp_signal_set Sagi Maimon
2025-04-15  7:51 ` Vadim Fedorenko
2025-04-17  1:31 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).