summaryrefslogtreecommitdiffstats
path: root/drivers/ptp
diff options
context:
space:
mode:
authorVladimir Oltean <olteanv@gmail.com>2020-08-05 03:10:47 +0300
committerDavid S. Miller <davem@davemloft.net>2020-08-05 12:06:44 -0700
commitc29f9aa35016729fc0cf72994e8b57f33466b64c (patch)
tree282a9f364a184ad6e776861d7bba5b3594a87687 /drivers/ptp
parent4c900a6b4e057fc9623240682988e203ae98ca94 (diff)
downloadlinux-stable-c29f9aa35016729fc0cf72994e8b57f33466b64c.tar.gz
linux-stable-c29f9aa35016729fc0cf72994e8b57f33466b64c.tar.bz2
linux-stable-c29f9aa35016729fc0cf72994e8b57f33466b64c.zip
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. Signed-off-by: Vladimir Oltean <olteanv@gmail.com> Acked-by: Richard Cochran <richardcochran@gmail.com> Acked-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/ptp')
-rw-r--r--drivers/ptp/ptp_chardev.c13
1 files changed, 13 insertions, 0 deletions
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;