From: Vladimir Oltean <olteanv@gmail.com>
To: Richard Cochran <richardcochran@gmail.com>
Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org,
jacob.e.keller@intel.com
Subject: Re: [PATCH net-next] ptp: only allow phase values lower than 1 period
Date: Wed, 5 Aug 2020 02:40:52 +0300 [thread overview]
Message-ID: <20200804234052.z54jncpjissagex5@skbuf> (raw)
In-Reply-To: <20200804232335.GA27679@hoboy>
On Tue, Aug 04, 2020 at 04:23:35PM -0700, Richard Cochran wrote:
> On Mon, Aug 03, 2020 at 10:49:21PM +0300, Vladimir Oltean wrote:
> > @@ -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 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;
> > + }
>
> So if perout->period={1,0} and perout->phase={1,0} then the phase has
> wrapped 360 degrees back to zero.
>
> Shouldn't this code catch that case as well?
>
> So why not test for (perout->phase.nsec >= perout->period.nsec) instead?
>
> Thanks,
> Richard
Oof, I guess this is what one would call 'brain fart'. In my mind,
checking for equality between period and phase required an extra 'if',
which I was reluctant to add (or to even think about, it seems). I
converted the nsec check to >= and it works as it should (I checked with
a modified ts2phc).
ts2phc[326.764]: config item /dev/ptp1.ts2phc.perout_phase is 1000000000
ts2phc[326.764]: config item /dev/ptp1.ts2phc.pulsewidth is 500000000
ts2phc[326.764]: PTP_PEROUT_REQUEST2 failed: Numerical result out of range
I'm sending a v2 with your change very soon.
Thanks.
-Vladimir
prev parent reply other threads:[~2020-08-04 23:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-03 19:49 [PATCH net-next] ptp: only allow phase values lower than 1 period Vladimir Oltean
2020-08-04 1:18 ` David Miller
2020-08-04 23:04 ` David Miller
2020-08-04 23:23 ` Richard Cochran
2020-08-04 23:40 ` Vladimir Oltean [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200804234052.z54jncpjissagex5@skbuf \
--to=olteanv@gmail.com \
--cc=davem@davemloft.net \
--cc=jacob.e.keller@intel.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox