* [PATCH net v2] net: phy: mscc: Fix memory leak when using one step timestamping
@ 2025-05-22 11:57 Horatiu Vultur
2025-05-22 12:39 ` Antoine Tenart
2025-05-28 2:30 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Horatiu Vultur @ 2025-05-22 11:57 UTC (permalink / raw)
To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran, kory.maincent, shannon.nelson, rrameshbabu, viro,
quentin.schulz, atenart
Cc: netdev, linux-kernel, Horatiu Vultur
Fix memory leak when running one-step timestamping. When running
one-step sync timestamping, the HW is configured to insert the TX time
into the frame, so there is no reason to keep the skb anymore. As in
this case the HW will never generate an interrupt to say that the frame
was timestamped, then the frame will never released.
Fix this by freeing the frame in case of one-step timestamping.
Fixes: 7d272e63e0979d ("net: phy: mscc: timestamping and PHC support")
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
v1->v2: Free the skb also when ptp is not configured
---
drivers/net/phy/mscc/mscc_ptp.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/mscc/mscc_ptp.c b/drivers/net/phy/mscc/mscc_ptp.c
index ed8fb14a7f215..6f96f2679f0bf 100644
--- a/drivers/net/phy/mscc/mscc_ptp.c
+++ b/drivers/net/phy/mscc/mscc_ptp.c
@@ -1166,18 +1166,24 @@ static void vsc85xx_txtstamp(struct mii_timestamper *mii_ts,
container_of(mii_ts, struct vsc8531_private, mii_ts);
if (!vsc8531->ptp->configured)
- return;
+ goto out;
- if (vsc8531->ptp->tx_type == HWTSTAMP_TX_OFF) {
- kfree_skb(skb);
- return;
- }
+ if (vsc8531->ptp->tx_type == HWTSTAMP_TX_OFF)
+ goto out;
+
+ if (vsc8531->ptp->tx_type == HWTSTAMP_TX_ONESTEP_SYNC)
+ if (ptp_msg_is_sync(skb, type))
+ goto out;
skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
mutex_lock(&vsc8531->ts_lock);
__skb_queue_tail(&vsc8531->ptp->tx_queue, skb);
mutex_unlock(&vsc8531->ts_lock);
+ return;
+
+out:
+ kfree_skb(skb);
}
static bool vsc85xx_rxtstamp(struct mii_timestamper *mii_ts,
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net: phy: mscc: Fix memory leak when using one step timestamping
2025-05-22 11:57 [PATCH net v2] net: phy: mscc: Fix memory leak when using one step timestamping Horatiu Vultur
@ 2025-05-22 12:39 ` Antoine Tenart
2025-05-28 2:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Antoine Tenart @ 2025-05-22 12:39 UTC (permalink / raw)
To: Horatiu Vultur
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran, kory.maincent, shannon.nelson, rrameshbabu, viro,
quentin.schulz, netdev, linux-kernel
On Thu, May 22, 2025 at 01:57:22PM +0200, Horatiu Vultur wrote:
> Fix memory leak when running one-step timestamping. When running
> one-step sync timestamping, the HW is configured to insert the TX time
> into the frame, so there is no reason to keep the skb anymore. As in
> this case the HW will never generate an interrupt to say that the frame
> was timestamped, then the frame will never released.
> Fix this by freeing the frame in case of one-step timestamping.
>
> Fixes: 7d272e63e0979d ("net: phy: mscc: timestamping and PHC support")
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
>
> ---
> v1->v2: Free the skb also when ptp is not configured
> ---
> drivers/net/phy/mscc/mscc_ptp.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/phy/mscc/mscc_ptp.c b/drivers/net/phy/mscc/mscc_ptp.c
> index ed8fb14a7f215..6f96f2679f0bf 100644
> --- a/drivers/net/phy/mscc/mscc_ptp.c
> +++ b/drivers/net/phy/mscc/mscc_ptp.c
> @@ -1166,18 +1166,24 @@ static void vsc85xx_txtstamp(struct mii_timestamper *mii_ts,
> container_of(mii_ts, struct vsc8531_private, mii_ts);
>
> if (!vsc8531->ptp->configured)
> - return;
> + goto out;
>
> - if (vsc8531->ptp->tx_type == HWTSTAMP_TX_OFF) {
> - kfree_skb(skb);
> - return;
> - }
> + if (vsc8531->ptp->tx_type == HWTSTAMP_TX_OFF)
> + goto out;
> +
> + if (vsc8531->ptp->tx_type == HWTSTAMP_TX_ONESTEP_SYNC)
> + if (ptp_msg_is_sync(skb, type))
> + goto out;
nit: you can combine the two checks and avoid having nested if
statements.
> skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
>
> mutex_lock(&vsc8531->ts_lock);
> __skb_queue_tail(&vsc8531->ptp->tx_queue, skb);
> mutex_unlock(&vsc8531->ts_lock);
> + return;
> +
> +out:
> + kfree_skb(skb);
> }
>
> static bool vsc85xx_rxtstamp(struct mii_timestamper *mii_ts,
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net: phy: mscc: Fix memory leak when using one step timestamping
2025-05-22 11:57 [PATCH net v2] net: phy: mscc: Fix memory leak when using one step timestamping Horatiu Vultur
2025-05-22 12:39 ` Antoine Tenart
@ 2025-05-28 2:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-05-28 2:30 UTC (permalink / raw)
To: Horatiu Vultur
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran, kory.maincent, shannon.nelson, rrameshbabu, viro,
quentin.schulz, atenart, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 22 May 2025 13:57:22 +0200 you wrote:
> Fix memory leak when running one-step timestamping. When running
> one-step sync timestamping, the HW is configured to insert the TX time
> into the frame, so there is no reason to keep the skb anymore. As in
> this case the HW will never generate an interrupt to say that the frame
> was timestamped, then the frame will never released.
> Fix this by freeing the frame in case of one-step timestamping.
>
> [...]
Here is the summary with links:
- [net,v2] net: phy: mscc: Fix memory leak when using one step timestamping
https://git.kernel.org/netdev/net/c/846992645b25
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-28 2:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-22 11:57 [PATCH net v2] net: phy: mscc: Fix memory leak when using one step timestamping Horatiu Vultur
2025-05-22 12:39 ` Antoine Tenart
2025-05-28 2:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®