From: Simon Horman <horms@kernel.org>
To: Min Li <lnimi@hotmail.com>
Cc: richardcochran@gmail.com, lee@kernel.org,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Min Li <min.li.xe@renesas.com>
Subject: Re: [PATCH net-next v2 2/2] ptp: add FemtoClock3 Wireless as ptp hardware clock
Date: Thu, 30 Nov 2023 17:11:26 +0000 [thread overview]
Message-ID: <20231130171126.GH32077@kernel.org> (raw)
In-Reply-To: <PH7PR03MB7064FC8C284D83E9C34B8C08A083A@PH7PR03MB7064.namprd03.prod.outlook.com>
On Wed, Nov 29, 2023 at 03:48:06PM -0500, Min Li wrote:
> From: Min Li <min.li.xe@renesas.com>
>
> The RENESAS FemtoClock3 Wireless is a high-performance jitter attenuator,
> frequency translator, and clock synthesizer. The device is comprised of 3
> digital PLLs (DPLL) to track CLKIN inputs and three independent low phase
> noise fractional output dividers (FOD) that output low phase noise clocks.
>
> FemtoClock3 supports one Time Synchronization (Time Sync) channel to enable
> an external processor to control the phase and frequency of the Time Sync
> channel and to take phase measurements using the TDC. Intended applications
> are synchronization using the precision time protocol (PTP) and
> synchronization with 0.5 Hz and 1 Hz signals from GNSS.
>
> Signed-off-by: Min Li <min.li.xe@renesas.com>
Hi Min Li,
some minor feedback from my side.
...
> diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile
...
> +static inline s64 ns2counters(struct idtfc3 *idtfc3, s64 nsec, u32 *sub_ns)
> +{
> + s64 sync;
> + s32 rem;
> +
> + if (likely(nsec > 0)) {
> + sync = div_u64_rem(nsec, idtfc3->ns_per_sync, &rem);
> + *sub_ns = rem;
> + } else if (nsec < 0) {
> + sync = -div_u64_rem(-nsec - 1, idtfc3->ns_per_sync, &rem) - 1;
> + *sub_ns = idtfc3->ns_per_sync - rem - 1;
> + }
> +
> + return sync * idtfc3->ns_per_sync;
Perhaps it cannot occur, but if nsec is exactly 0, then
sync is uninitialised here.
Flagged by clang-17 W=1 build, and Smatch.
> +}
...
> +static int _idtfc3_settime(struct idtfc3 *idtfc3, const struct timespec64 *ts)
> +{
> + s64 offset_ns, now_ns, sync_ns;
> + u32 counter, sub_ns;
> + int now;
> +
> + if (timespec64_valid(ts) == false) {
> + dev_err(idtfc3->dev, "%s: invalid timespec", __func__);
> + return -EINVAL;
> + }
> +
> + now = idtfc3_read_subcounter(idtfc3);
> + if (now < 0)
> + return now;
> +
> + offset_ns = (idtfc3->sub_sync_count - now) * idtfc3->ns_per_counter;
> + now_ns = timespec64_to_ns(ts);
> + sync_ns = ns2counters(idtfc3, offset_ns + now_ns, &sub_ns);
sync_ns is set here but otherwise unused.
Perhaps the assignment can be dropped and sync_ns removed from this
function?
As flagged by gcc-13 W=1 build and Smatch.
> +
> + counter = sub_ns / idtfc3->ns_per_counter;
> + return idtfc3_timecounter_update(idtfc3, counter, now_ns);
> +}
...
next prev parent reply other threads:[~2023-11-30 17:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20231129204806.14539-1-lnimi@hotmail.com>
2023-11-29 20:48 ` [PATCH net-next v2 2/2] ptp: add FemtoClock3 Wireless as ptp hardware clock Min Li
2023-11-30 17:11 ` Simon Horman [this message]
2023-12-07 14:29 ` Lee Jones
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=20231130171126.GH32077@kernel.org \
--to=horms@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lnimi@hotmail.com \
--cc=min.li.xe@renesas.com \
--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;
as well as URLs for NNTP newsgroup(s).