Skip to contentSkip to conversation

ptp: only allow phase values lower than 1 period

PATCH Applied Vladimir Oltean 4 participants 4 messages Aug 5, 2020

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

PATCH v3 1/1 ptp: only allow phase values lower than 1 period

The way we define the phase (the difference between the time of the signal's rising edge, and the closest integer multiple of the period), it doesn't make sense to have a phase value equal or larger than 1 period.

So deny these settings coming from the user.

---
Changes in v3:
Adjust the comments to cover the equality case.

Changes in v2:
Be sure to also deny the case where the period is equal to the phase. This represents a 360 degree offset, which is equivalent to a phase of zero, so it should be rejected on the grounds of having a modulo equivalent as well.

 drivers/ptp/ptp_chardev.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/ptp/ptp_chardev.c +13 -0
index e0e6f85966e1..af3bc65c4595 100644
@@ -218,6 +218,19 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 					break;
 				}
 			}
+			if (perout->flags & PTP_PEROUT_PHASE) {
+				/*
+				 * The phase should be specified modulo the
+				 * period, therefore anything equal or larger
+				 * than 1 period is invalid.
+				 */
+				if (perout->phase.sec > perout->period.sec ||
+				    (perout->phase.sec == perout->period.sec &&
+				     perout->phase.nsec >= perout->period.nsec)) {
+					err = -ERANGE;
+					break;
+				}
+			}
 		} else if (cmd == PTP_PEROUT_REQUEST) {
 			req.perout.flags &= PTP_PEROUT_V1_VALID_FLAGS;
 			req.perout.rsv[0] = 0;
Signature · 1 line
2.25.1
#2 lore raw
Quoted 17 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Tuesday, August 04, 2020 7:06 PM
To: Vladimir Oltean <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>
Subject: Re: [PATCH v3 net-next] ptp: only allow phase values lower than 1 period

Quoted 5 lines · Vladimir Oltean

The way we define the phase (the difference between the time of the signal's rising edge, and the closest integer multiple of the period), it doesn't make sense to have a phase value equal or larger than 1 period.

Quoted 5 lines
Quoted 3 lines

So deny these settings coming from the user.

Thanks!

maintainer Applied
#3 lore raw
In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>
Date: Wed, 5 Aug 2020 03:10:47 +0300

Quoted 8 lines

The way we define the phase (the difference between the time of the signal's rising edge, and the closest integer multiple of the period), it doesn't make sense to have a phase value equal or larger than 1 period.

So deny these settings coming from the user.

Applied, thank you.