netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 net-next] ptp: only allow phase values lower than 1 period
@ 2020-08-05  0:10 Vladimir Oltean
  2020-08-05  2:05 ` Richard Cochran
  2020-08-05 19:07 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Vladimir Oltean @ 2020-08-05  0:10 UTC (permalink / raw)
  To: kuba, davem, netdev; +Cc: richardcochran, jacob.e.keller

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.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
---
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(+)

diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index e0e6f85966e1..af3bc65c4595 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -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;
-- 
2.25.1


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

* Re: [PATCH v3 net-next] ptp: only allow phase values lower than 1 period
  2020-08-05  0:10 [PATCH v3 net-next] ptp: only allow phase values lower than 1 period Vladimir Oltean
@ 2020-08-05  2:05 ` Richard Cochran
  2020-08-05 15:47   ` Keller, Jacob E
  2020-08-05 19:07 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Richard Cochran @ 2020-08-05  2:05 UTC (permalink / raw)
  To: Vladimir Oltean; +Cc: kuba, davem, netdev, jacob.e.keller

On Wed, Aug 05, 2020 at 03:10:47AM +0300, Vladimir Oltean wrote:
> 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.
> 
> Signed-off-by: Vladimir Oltean <olteanv@gmail.com>

Acked-by: Richard Cochran <richardcochran@gmail.com>

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

* RE: [PATCH v3 net-next] ptp: only allow phase values lower than 1 period
  2020-08-05  2:05 ` Richard Cochran
@ 2020-08-05 15:47   ` Keller, Jacob E
  0 siblings, 0 replies; 4+ messages in thread
From: Keller, Jacob E @ 2020-08-05 15:47 UTC (permalink / raw)
  To: Richard Cochran, Vladimir Oltean; +Cc: kuba, davem, netdev



> -----Original Message-----
> From: Richard Cochran <richardcochran@gmail.com>
> Sent: Tuesday, August 04, 2020 7:06 PM
> To: Vladimir Oltean <olteanv@gmail.com>
> Cc: kuba@kernel.org; davem@davemloft.net; netdev@vger.kernel.org; Keller,
> Jacob E <jacob.e.keller@intel.com>
> Subject: Re: [PATCH v3 net-next] ptp: only allow phase values lower than 1
> period
> 
> On Wed, Aug 05, 2020 at 03:10:47AM +0300, Vladimir Oltean wrote:
> > 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.
> >
> > Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
> 
> Acked-by: Richard Cochran <richardcochran@gmail.com>

Acked-by: Jacob Keller <jacob.e.keller@intel.com>

Thanks!

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

* Re: [PATCH v3 net-next] ptp: only allow phase values lower than 1 period
  2020-08-05  0:10 [PATCH v3 net-next] ptp: only allow phase values lower than 1 period Vladimir Oltean
  2020-08-05  2:05 ` Richard Cochran
@ 2020-08-05 19:07 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2020-08-05 19:07 UTC (permalink / raw)
  To: olteanv; +Cc: kuba, netdev, richardcochran, jacob.e.keller

From: Vladimir Oltean <olteanv@gmail.com>
Date: Wed,  5 Aug 2020 03:10:47 +0300

> 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.
> 
> Signed-off-by: Vladimir Oltean <olteanv@gmail.com>

Applied, thank you.

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

end of thread, other threads:[~2020-08-05 19:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-05  0:10 [PATCH v3 net-next] ptp: only allow phase values lower than 1 period Vladimir Oltean
2020-08-05  2:05 ` Richard Cochran
2020-08-05 15:47   ` Keller, Jacob E
2020-08-05 19:07 ` David Miller

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).