Skip to content

Commit c29f9aa

Browse files
vladimirolteandavem330
authored andcommitted
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>
1 parent 4c900a6 commit c29f9aa

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

drivers/ptp/ptp_chardev.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
218218
break;
219219
}
220220
}
221+
if (perout->flags & PTP_PEROUT_PHASE) {
222+
/*
223+
* The phase should be specified modulo the
224+
* period, therefore anything equal or larger
225+
* than 1 period is invalid.
226+
*/
227+
if (perout->phase.sec > perout->period.sec ||
228+
(perout->phase.sec == perout->period.sec &&
229+
perout->phase.nsec >= perout->period.nsec)) {
230+
err = -ERANGE;
231+
break;
232+
}
233+
}
221234
} else if (cmd == PTP_PEROUT_REQUEST) {
222235
req.perout.flags &= PTP_PEROUT_V1_VALID_FLAGS;
223236
req.perout.rsv[0] = 0;

0 commit comments

Comments
 (0)