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 <[email protected]> Acked-by: Richard Cochran <[email protected]> Acked-by: Jacob Keller <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4c900a6 commit c29f9aa

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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)