From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: xuanqiang.luo@linux.dev, linux-renesas-soc@vger.kernel.org,
netdev@vger.kernel.org, niklas.soderlund@ragnatech.se,
kuba@kernel.org
Cc: paul@pbarker.dev, andrew+netdev@lunn.ch, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com, richardcochran@gmail.com,
masaru.nagai.vx@renesas.com, sergei.shtylyov@cogentembedded.com,
luoxuanqiang@kylinos.cn, stable@vger.kernel.org
Subject: Re: [PATCH net v3 1/2] net: ravb: handle unavailable PTP clock
Date: Thu, 6 Aug 2026 14:37:32 +0100 [thread overview]
Message-ID: <fa89cba0-e9e5-49af-beb9-13b2fa94ca19@linux.dev> (raw)
In-Reply-To: <20260806095126.57803-2-xuanqiang.luo@linux.dev>
On 06/08/2026 10:51, xuanqiang.luo@linux.dev wrote:
> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>
> The PTP clock is registered by ravb_open(), not ravb_probe(). Therefore,
> priv->ptp.clock is NULL between register_netdev() and the first open, and
> ethtool -T triggers a NULL dereference in ptp_clock_index().
>
> ptp_clock_register() may also return an error pointer, which can reach
> ptp_clock_index() or ptp_clock_unregister().
>
> Normalize registration errors to NULL and only query or unregister the
> clock when it is present. Leave phc_index at -1 when no PHC is registered,
> while preserving the static hardware timestamping capabilities.
>
> Fixes: a0d2f20650e8 ("Renesas Ethernet AVB PTP clock driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
> ---
> drivers/net/ethernet/renesas/ravb_main.c | 3 ++-
> drivers/net/ethernet/renesas/ravb_ptp.c | 12 ++++++++++--
> 2 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 5f88733094d0f..3a9d9f8718216 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -1779,7 +1779,8 @@ static int ravb_get_ts_info(struct net_device *ndev,
> (1 << HWTSTAMP_FILTER_NONE) |
> (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
> (1 << HWTSTAMP_FILTER_ALL);
> - info->phc_index = ptp_clock_index(priv->ptp.clock);
> + if (priv->ptp.clock)
> + info->phc_index = ptp_clock_index(priv->ptp.clock);
> }
>
> return 0;
> diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
> index 226c6c0ab945b..eaf07cb8eadfa 100644
> --- a/drivers/net/ethernet/renesas/ravb_ptp.c
> +++ b/drivers/net/ethernet/renesas/ravb_ptp.c
> @@ -315,6 +315,7 @@ void ravb_ptp_interrupt(struct net_device *ndev)
> void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev)
> {
> struct ravb_private *priv = netdev_priv(ndev);
> + struct ptp_clock *clock;
> unsigned long flags;
>
> priv->ptp.info = ravb_ptp_info;
> @@ -327,7 +328,13 @@ void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev)
> ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP);
> spin_unlock_irqrestore(&priv->lock, flags);
>
> - priv->ptp.clock = ptp_clock_register(&priv->ptp.info, &pdev->dev);
> + clock = ptp_clock_register(&priv->ptp.info, &pdev->dev);
> + if (IS_ERR(clock)) {
> + netdev_err(ndev, "failed to register PTP clock: %pe\n", clock);
> + clock = NULL;
> + }
> +
> + priv->ptp.clock = clock;
> }
>
> void ravb_ptp_stop(struct net_device *ndev)
> @@ -337,5 +344,6 @@ void ravb_ptp_stop(struct net_device *ndev)
> ravb_write(ndev, 0, GIC);
> ravb_write(ndev, 0, GIS);
>
> - ptp_clock_unregister(priv->ptp.clock);
> + if (priv->ptp.clock)
> + ptp_clock_unregister(priv->ptp.clock);
> }
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
next prev parent reply other threads:[~2026-08-06 13:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 9:51 [PATCH net v3 0/2] net: ravb: fix PTP clock lifetime xuanqiang.luo
2026-08-06 9:51 ` [PATCH net v3 1/2] net: ravb: handle unavailable PTP clock xuanqiang.luo
2026-08-06 13:37 ` Vadim Fedorenko [this message]
2026-08-06 9:51 ` [PATCH net v3 2/2] net: ravb: serialize PTP clock teardown xuanqiang.luo
2026-08-06 22:34 ` Vadim Fedorenko
2026-08-07 10:14 ` luoxuanqiang
2026-08-07 14:51 ` Vadim Fedorenko
2026-08-09 10:29 ` luoxuanqiang
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=fa89cba0-e9e5-49af-beb9-13b2fa94ca19@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=luoxuanqiang@kylinos.cn \
--cc=masaru.nagai.vx@renesas.com \
--cc=netdev@vger.kernel.org \
--cc=niklas.soderlund@ragnatech.se \
--cc=pabeni@redhat.com \
--cc=paul@pbarker.dev \
--cc=richardcochran@gmail.com \
--cc=sergei.shtylyov@cogentembedded.com \
--cc=stable@vger.kernel.org \
--cc=xuanqiang.luo@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.