Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org,
	wsa+renesas@sang-engineering.com, robh@kernel.org
Subject: Re: [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop
Date: Thu, 03 Sep 2026 08:47:57 +0000	[thread overview]
Message-ID: <20260903084757.9E74B1F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260902084703.3228504-4-niklas.soderlund+renesas@ragnatech.se>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing PTP clock unregistration for `ccc_gac` (Gen3) devices on the `ravb_open()` error path leads to a Use-After-Free.
- [High] Missing PTP clock driver teardown for `gptp` (Gen2) devices on hardware timeout leads to a Use-After-Free.
- [Medium] Silent loss of PTP clock functionality during TX timeout recovery for `gptp` devices.
--

commit 13e73cf3cf26d2c226a9c19d3728cc27d5cffb72
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

net: ethernet: ravb: Simplify gPTP start and stop

This commit simplifies the gPTP start and stop logic by folding the gptp flag
handling directly into ravb_dmac_init() and ravb_stop_dma(). It aims to
control the clock for gptp devices in tandem with the AVB-DMAC, while leaving
ccc_gac devices tied to device open/close operations. However, this
refactoring appears to introduce regressions in error handling and timeout
recovery paths.

> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index a89f6fe7866fe..2d0022a4f85c3 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
[ ... ]
> @@ -1115,6 +1123,10 @@ static int ravb_stop_dma(struct net_device *ndev)
>  			netdev_err(ndev, "failed to stop AXI BUS\n");
>  	}
>  
> +	/* Stop PTP Clock driver */
> +	if (info->gptp)
> +		ravb_ptp_stop(ndev);
> +
>  	/* Stop AVB-DMAC process */
>  	return ravb_set_opmode(ndev, CCC_OPC_CONFIG);
>  }

[Severity: High]
Can a hardware timeout cause a use-after-free by skipping the PTP clock
teardown?

Earlier in ravb_stop_dma(), there are multiple ravb_wait() hardware polling
loops. If any of these wait loops time out, the function returns an error
immediately, bypassing this new ravb_ptp_stop() call. During a module unload
or interface close, if ravb_stop_dma() fails, teardown continues but the PTP
clock remains registered. Does this leave the /dev/ptp* device pointing to
freed memory?

[ ... ]
> @@ -1974,9 +1980,6 @@ static int ravb_open(struct net_device *ndev)
>  	return 0;
>  
>  out_ptp_stop:
> -	/* Stop PTP Clock driver */
> -	if (info->gptp || info->ccc_gac)
> -		ravb_ptp_stop(ndev);
>  	ravb_stop_dma(ndev);
>  out_set_reset:
>  	ravb_set_opmode(ndev, CCC_OPC_RESET);

[Severity: High]
Does this error path leak the PTP clock driver for ccc_gac (Gen3) devices?

When ravb_ptp_init() is called successfully but a subsequent step like
ravb_phy_start() fails, the code jumps here to out_ptp_stop. Since
ravb_stop_dma() only stops the clock for gptp devices, the clock remains
registered for ccc_gac devices. If the network device is subsequently freed
by a module unload, could this lead to a use-after-free when userspace
accesses the dangling PTP device?

[ ... ]
> @@ -2056,10 +2055,6 @@ static void ravb_tx_timeout_work(struct work_struct *work)
>  	ravb_emac_init(ndev);
>  
>  out:
> -	/* Initialise PTP Clock driver */
> -	if (info->gptp)
> -		ravb_ptp_init(ndev, priv->pdev);
> -
>  	netif_tx_start_all_queues(ndev);
>  
>  out_unlock:

[Severity: Medium]
Does removing this initialization cause a silent loss of PTP clock
functionality during TX timeout recovery?

If ravb_stop_dma() successfully stops the PTP clock but fails at its final
step (ravb_set_opmode()), it returns an error. The error path in
ravb_tx_timeout_work() jumps to the out label, re-enables queues, and
aborts full re-initialization.

Since ravb_ptp_init() is no longer called at the out label, does the PTP
clock remain permanently stopped and unregistered until the interface is
manually brought down and up again?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=3

  reply	other threads:[~2026-09-03  8:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02  8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
2026-09-02  8:46 ` [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore Niklas Söderlund
2026-09-03  8:47   ` sashiko-bot
2026-09-03 11:11     ` Niklas Söderlund
2026-09-02  8:46 ` [PATCH net-next v3 02/10] net: ethernet: ravb: Move programming of gPTP timer interval Niklas Söderlund
2026-09-03  8:47   ` sashiko-bot
2026-09-02  8:46 ` [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop Niklas Söderlund
2026-09-03  8:47   ` sashiko-bot [this message]
2026-09-02  8:46 ` [PATCH net-next v3 04/10] net: ethernet: ravb: Remove redundant argument to ravb_ptp_init() Niklas Söderlund
2026-09-02  8:46 ` [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register() Niklas Söderlund
2026-09-03  8:47   ` sashiko-bot
2026-09-03 11:35     ` Niklas Söderlund
2026-09-02  8:46 ` [PATCH net-next v3 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks Niklas Söderlund
2026-09-03  8:47   ` sashiko-bot
2026-09-02  8:47 ` [PATCH net-next v3 07/10] net: ethernet: ravb: Add callback for gPTP probe Niklas Söderlund
2026-09-03  8:47   ` sashiko-bot
2026-09-02  8:47 ` [PATCH net-next v3 08/10] net: ethernet: ravb: Add callback for gPTP clock index Niklas Söderlund
2026-09-03  8:47   ` sashiko-bot
2026-09-02  8:47 ` [PATCH net-next v3 09/10] dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4 Niklas Söderlund
2026-09-02  8:47 ` [PATCH net-next v3 10/10] net: ethernet: ravb: Add gPTP support " Niklas Söderlund
2026-09-03  8:48   ` 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=20260903084757.9E74B1F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.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