From: sashiko-bot@kernel.org
To: wei.fang@oss.nxp.com
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH net-next 3/7] ptp: netc: export netc_timer_get_current_time() for cross-driver use
Date: Wed, 29 Jul 2026 10:43:14 +0000 [thread overview]
Message-ID: <20260729104314.BEB451F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260728104548.3301214-4-wei.fang@oss.nxp.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Time-of-Check to Time-of-Use (TOCTOU) race condition in netc_timer_get_current_time() leads to Use-After-Free and invalid MMIO access during concurrent unbind.
- [High] Premature publishing of driver data in netc_timer_pci_probe() causes netc_timer_get_current_time() to access uninitialized locks and hardware registers.
- [Low] Build/linker error due to using IS_ENABLED() instead of IS_REACHABLE() for an exported cross-driver symbol.
--
--- Patch [3]: [PATCH net-next 3/7] ptp: netc: export netc_timer_get_current_time() for cross-driver use ---
commit 397844577b2034cd8a6a870bc6609d9217d7fc38
Author: Wei Fang <wei.fang@nxp.com>
ptp: netc: export netc_timer_get_current_time() for cross-driver use
This commit adds and exports netc_timer_get_current_time() to allow the NETC
Switch driver to read the current PTP time from the NETC Timer. It also
provides a stub declaration when the timer configuration is disabled.
> diff --git a/drivers/ptp/ptp_netc.c b/drivers/ptp/ptp_netc.c
> index 072809ea7922c..60e64542314b1 100644
> --- a/drivers/ptp/ptp_netc.c
> +++ b/drivers/ptp/ptp_netc.c
[ ... ]
> @@ -165,6 +165,23 @@ static u64 netc_timer_cur_time_read(struct netc_timer *priv)
> return netc_timer_rd64(priv, NETC_TMR_CUR_TIME_L);
> }
>
> +u64 netc_timer_get_current_time(struct pci_dev *pdev)
> +{
> + struct netc_timer *priv = pci_get_drvdata(pdev);
[Severity: High]
Does this function assume the driver data is fully initialized if priv is
not NULL?
In netc_timer_pci_probe(), pci_set_drvdata() is called before the spinlock
is initialized in netc_timer_probe(). If a concurrent caller fetches the
driver data here while the timer is still probing, could it attempt to
acquire an uninitialized spinlock or read from unconfigured hardware?
> + unsigned long flags;
> + u64 cur_time;
> +
> + if (!priv)
> + return 0;
> +
[Severity: Critical]
Is this lockless check sufficient to prevent a use-after-free if the timer
driver is unbound concurrently?
If a concurrent thread unbinds the timer driver via sysfs right after this
check passes, the driver's remove() callback could execute and unmap the
MMIO region. The device core's devres cleanup would then free the priv
pointer before clearing the driver data.
Does this mean the caller could then attempt to acquire a freed spinlock
and read from unmapped MMIO memory?
> + spin_lock_irqsave(&priv->lock, flags);
> + cur_time = netc_timer_cur_time_read(priv);
> + spin_unlock_irqrestore(&priv->lock, flags);
> +
> + return cur_time;
> +}
> +EXPORT_SYMBOL_GPL(netc_timer_get_current_time);
[ ... ]
> diff --git a/include/linux/fsl/netc_global.h b/include/linux/fsl/netc_global.h
> index 5b8ff528d3699..91441cb35bc28 100644
> --- a/include/linux/fsl/netc_global.h
> +++ b/include/linux/fsl/netc_global.h
> @@ -22,4 +22,13 @@ static inline u64 netc_read64(void __iomem *reg)
> return ioread64(reg);
> }
>
> +#if IS_ENABLED(CONFIG_PTP_NETC_V4_TIMER)
[Severity: Low]
Will this cause a linker error if the calling driver is built-in (=y) but
the timer driver is built as a module (=m)?
Since IS_ENABLED() evaluates to true when the config is a module, the
fallback stub won't be provided. The built-in caller would then be unable
to resolve the modular symbol during linking.
Should this use IS_REACHABLE() instead?
> +u64 netc_timer_get_current_time(struct pci_dev *timer_dev);
> +#else
> +static inline u64 netc_timer_get_current_time(struct pci_dev *timer_dev)
> +{
> + return 0;
> +}
> +#endif
> +
> #endif
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728104548.3301214-1-wei.fang@oss.nxp.com?part=3
next prev parent reply other threads:[~2026-07-29 10:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 10:45 [PATCH net-next 0/7] net: dsa: netc: add PTP support for NETC switch wei.fang
2026-07-28 10:45 ` [PATCH net-next 1/7] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access wei.fang
2026-07-29 10:43 ` sashiko-bot
2026-07-28 10:45 ` [PATCH net-next 2/7] ptp: netc: remove unnecessary pcie_flr() call in probe wei.fang
2026-07-29 10:43 ` sashiko-bot
2026-07-28 10:45 ` [PATCH net-next 3/7] ptp: netc: export netc_timer_get_current_time() for cross-driver use wei.fang
2026-07-29 10:43 ` sashiko-bot [this message]
2026-07-28 10:45 ` [PATCH net-next 4/7] net: dsa: netc: use entry ID instead of pointer to track host flood rule wei.fang
2026-07-28 10:45 ` [PATCH net-next 5/7] net: dsa: netc: enable ingress port filtering lookup by default wei.fang
2026-07-28 10:45 ` [PATCH net-next 6/7] net: dsa: netc: add PTP two-step timestamping support wei.fang
2026-07-29 10:43 ` sashiko-bot
2026-07-29 13:41 ` Vadim Fedorenko
2026-07-28 10:45 ` [PATCH net-next 7/7] net: dsa: netc: add PTP one-step " wei.fang
2026-07-29 10:43 ` sashiko-bot
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=20260729104314.BEB451F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wei.fang@oss.nxp.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