FAILED: patch "[PATCH] net: ravb: avoid dereferencing an invalid PTP clock" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 1f77af0aaf277413ff32f6ff8c2c4282bd64c897
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090322-boss-emu-7014@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 1f77af0aaf277413ff32f6ff8c2c4282bd64c897 Mon Sep 17 00:00:00 2001
From: Xuanqiang Luo <[email protected]>
Date: Tue, 11 Aug 2026 18:37:32 +0800
Subject: [PATCH] net: ravb: avoid dereferencing an invalid PTP clock
The PTP clock is unavailable before the first open, so querying its index can dereference a NULL pointer. Registration failures can also leave an error pointer in priv->ptp.clock.
Cache the PHC index separately and report -1 while no clock is registered. Normalize registration errors to NULL and preserve the static timestamping capabilities.
drivers/net/ethernet/renesas/ravb.h +1 -0
@@ -1028,6 +1028,7 @@ struct ravb_ptp_perout {struct ravb_ptp {struct ptp_clock *clock;struct ptp_clock_info info; +int phc_index;u32 default_addend;u32 current_addend;int extts[N_EXT_TS ];
drivers/net/ethernet/renesas/ravb_main.c +2 -1
@@ -1779,7 +1779,7 @@ 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); + info->phc_index =READ_ONCE (priv->ptp.phc_index); }return 0 ;
@@ -2953,6 +2953,7 @@ static int ravb_probe(struct platform_device *pdev) priv->rstc = rstc; priv->ndev = ndev; priv->pdev = pdev; + priv->ptp.phc_index =-1 ; priv->num_tx_ring[RAVB_BE ] =BE_TX_RING_SIZE ; priv->num_rx_ring[RAVB_BE ] =BE_RX_RING_SIZE ;if (info->nc_queues) {
drivers/net/ethernet/renesas/ravb_ptp.c +13 -2
@@ -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,15 @@ 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; +if (clock) +WRITE_ONCE (priv->ptp.phc_index,ptp_clock_index (clock)); }void ravb_ptp_stop (struct net_device *ndev)
@@ -337,5 +346,7 @@ void ravb_ptp_stop(struct net_device *ndev)ravb_write (ndev,0 ,GIC );ravb_write (ndev,0 ,GIS ); -ptp_clock_unregister (priv->ptp.clock); +WRITE_ONCE (priv->ptp.phc_index,-1 ); +if (priv->ptp.clock) +ptp_clock_unregister (priv->ptp.clock); }
Sasha Levin
maintainerPATCH 1/3 ravb: Remove setting of RX software timestamp
From: Gal Pressman <[email protected]>
[ Upstream commit 277901ee3a2620679e2c8797377d2a72f4358068 ]
The responsibility for reporting of RX software timestamp has moved to the core layer (see __ethtool_get_ts_info()), remove usage from the device drivers.
Stable-dep-of: 1f77af0aaf27 ("net: ravb: avoid dereferencing an invalid PTP clock")
--- drivers/net/ethernet/renesas/ravb_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/renesas/ravb_main.c +2 -2
@@ -1325,8 +1325,6 @@ static int ravb_get_ts_info(struct net_device *ndev, info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | -SOF_TIMESTAMPING_RX_SOFTWARE | -SOF_TIMESTAMPING_SOFTWARE |SOF_TIMESTAMPING_TX_HARDWARE |SOF_TIMESTAMPING_RX_HARDWARE |SOF_TIMESTAMPING_RAW_HARDWARE ;
@@ -1337,6 +1335,8 @@ static int ravb_get_ts_info(struct net_device *ndev, (1 <<HWTSTAMP_FILTER_ALL );if (hw_info->gptp || hw_info->ccc_gac) info->phc_index =ptp_clock_index (priv->ptp.clock); +else + info->phc_index =0 ;return 0 ; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 net: ravb: Only advertise Rx/Tx timestamps if hardware supports it
From: Niklas Söderlund <[email protected]>
[ Upstream commit 126e799602f45e9ce1ded03ee9eadda68bf470e0 ]
Recent work moving the reporting of Rx software timestamps to the core
[1] highlighted an issue where hardware time stamping was advertised for the platforms where it is not supported.
Fix this by covering advertising support for hardware timestamps only if the hardware supports it. Due to the Tx implementation in RAVB software Tx timestamping is also only considered if the hardware supports hardware timestamps. This should be addressed in future, but this fix only reflects what the driver currently implements.
1. Commit 277901ee3a26 ("ravb: Remove setting of RX software timestamp")
Stable-dep-of: 1f77af0aaf27 ("net: ravb: avoid dereferencing an invalid PTP clock")
--- drivers/net/ethernet/renesas/ravb_main.c | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/net/ethernet/renesas/ravb_main.c +12 -13
@@ -1323,20 +1323,19 @@ static int ravb_get_ts_info(struct net_device *ndev,struct ravb_private *priv =netdev_priv (ndev);const struct ravb_hw_info *hw_info = priv->info; - info->so_timestamping = -SOF_TIMESTAMPING_TX_SOFTWARE | -SOF_TIMESTAMPING_TX_HARDWARE | -SOF_TIMESTAMPING_RX_HARDWARE | -SOF_TIMESTAMPING_RAW_HARDWARE ; - info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | (1 <<HWTSTAMP_TX_ON ); - info->rx_filters = - (1 <<HWTSTAMP_FILTER_NONE ) | - (1 <<HWTSTAMP_FILTER_PTP_V2_L2_EVENT ) | - (1 <<HWTSTAMP_FILTER_ALL ); -if (hw_info->gptp || hw_info->ccc_gac) +if (hw_info->gptp || hw_info->ccc_gac) { + info->so_timestamping = +SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | (1 <<HWTSTAMP_TX_ON ); + info->rx_filters = + (1 <<HWTSTAMP_FILTER_NONE ) | + (1 <<HWTSTAMP_FILTER_PTP_V2_L2_EVENT ) | + (1 <<HWTSTAMP_FILTER_ALL ); info->phc_index =ptp_clock_index (priv->ptp.clock); -else - info->phc_index =0 ; + }return 0 ; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 net: ravb: avoid dereferencing an invalid PTP clock
In reply to Sasha LevinFrom: Xuanqiang Luo <[email protected]>
[ Upstream commit 1f77af0aaf277413ff32f6ff8c2c4282bd64c897 ]
The PTP clock is unavailable before the first open, so querying its index can dereference a NULL pointer. Registration failures can also leave an error pointer in priv->ptp.clock.
Cache the PHC index separately and report -1 while no clock is registered. Normalize registration errors to NULL and preserve the static timestamping capabilities.
--- drivers/net/ethernet/renesas/ravb.h | 1 + drivers/net/ethernet/renesas/ravb_main.c | 3 ++- drivers/net/ethernet/renesas/ravb_ptp.c | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-)
drivers/net/ethernet/renesas/ravb.h +1 -0
@@ -973,6 +973,7 @@ struct ravb_ptp_perout {struct ravb_ptp {struct ptp_clock *clock;struct ptp_clock_info info; +int phc_index;u32 default_addend;u32 current_addend;int extts[N_EXT_TS ];
drivers/net/ethernet/renesas/ravb_main.c +2 -1
@@ -1334,7 +1334,7 @@ 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); + info->phc_index =READ_ONCE (priv->ptp.phc_index); }return 0 ;
@@ -2247,6 +2247,7 @@ static int ravb_probe(struct platform_device *pdev) priv->rstc = rstc; priv->ndev = ndev; priv->pdev = pdev; + priv->ptp.phc_index =-1 ; priv->num_tx_ring[RAVB_BE ] =BE_TX_RING_SIZE ; priv->num_rx_ring[RAVB_BE ] =BE_RX_RING_SIZE ; priv->num_tx_ring[RAVB_NC ] =NC_TX_RING_SIZE ;
drivers/net/ethernet/renesas/ravb_ptp.c +13 -2
@@ -332,6 +332,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;
@@ -344,7 +345,15 @@ 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; +if (clock) +WRITE_ONCE (priv->ptp.phc_index,ptp_clock_index (clock)); }void ravb_ptp_stop (struct net_device *ndev)
@@ -354,5 +363,7 @@ void ravb_ptp_stop(struct net_device *ndev)ravb_write (ndev,0 ,GIC );ravb_write (ndev,0 ,GIS ); -ptp_clock_unregister (priv->ptp.clock); +WRITE_ONCE (priv->ptp.phc_index,-1 ); +if (priv->ptp.clock) +ptp_clock_unregister (priv->ptp.clock); }
Signature · 1 line
2.53.0