Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Vladimir Oltean and committed by
David S. Miller
c29f9aa3 4c900a6b

+13
+13
drivers/ptp/ptp_chardev.c
··· 218 218 break; 219 219 } 220 220 } 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 + } 221 234 } else if (cmd == PTP_PEROUT_REQUEST) { 222 235 req.perout.flags &= PTP_PEROUT_V1_VALID_FLAGS; 223 236 req.perout.rsv[0] = 0;