RE: [PATCH net] net: fec: don't save PTP state if PTP is unsupported

From: Wei Fang
Date: Wed Oct 09 2024 - 08:48:57 EST


> -----Original Message-----
> From: Simon Horman <horms@xxxxxxxxxx>
> Sent: 2024年10月9日 19:55
> To: Wei Fang <wei.fang@xxxxxxx>
> Cc: davem@xxxxxxxxxxxxx; edumazet@xxxxxxxxxx; kuba@xxxxxxxxxx;
> pabeni@xxxxxxxxxx; richardcochran@xxxxxxxxx; csokas.bence@xxxxxxxxx;
> Shenwei Wang <shenwei.wang@xxxxxxx>; Clark Wang
> <xiaoning.wang@xxxxxxx>; linux@xxxxxxxxxxxx; imx@xxxxxxxxxxxxxxx;
> netdev@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH net] net: fec: don't save PTP state if PTP is unsupported
>
> On Tue, Oct 08, 2024 at 02:11:53PM +0800, Wei Fang wrote:
> > Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on
> > these platforms fec_ptp_init() is not called and the related members
> > in fep are not initialized. However, fec_ptp_save_state() is called
> > unconditionally, which causes the kernel to panic. Therefore, add a
> > condition so that fec_ptp_save_state() is not called if PTP is not
> > supported.
> >
> > Fixes: a1477dc87dc4 ("net: fec: Restart PPS after link state change")
> > Reported-by: Guenter Roeck <linux@xxxxxxxxxxxx>
> > Closes:
> https://lore.ker/
> nel.org%2Flkml%2F353e41fe-6bb4-4ee9-9980-2da2a9c1c508%40roeck-us.net
> %2F&data=05%7C02%7Cwei.fang%40nxp.com%7Cb10cac9ed8cd43284aae08
> dce85930cd%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63864
> 0716999752935%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLC
> JQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=1
> gxwnxNjk91xX7I%2Foco%2F4OhBbxNCryhDMo72O9Jkr2w%3D&reserved=0
> > Signed-off-by: Wei Fang <wei.fang@xxxxxxx>
> > ---
> > drivers/net/ethernet/freescale/fec_main.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> > index 60fb54231ead..1b55047c0237 100644
> > --- a/drivers/net/ethernet/freescale/fec_main.c
> > +++ b/drivers/net/ethernet/freescale/fec_main.c
> > @@ -1077,7 +1077,8 @@ fec_restart(struct net_device *ndev)
> > u32 rcntl = OPT_FRAME_SIZE | 0x04;
> > u32 ecntl = FEC_ECR_ETHEREN;
> >
> > - fec_ptp_save_state(fep);
> > + if (fep->bufdesc_ex)
> > + fec_ptp_save_state(fep);
>
> Hi,
>
> I am wondering if you considered adding this check to (the top of)
> fec_ptp_save_state. It seems like it would both lead to a smaller
> change and be less error-prone to use.
>

Yes, I considered this solution, but when I thought about it,
fec_ptp_save_state() and fec_ptp_restore_state() are a pair. If
the check is added to fec_ptp_save_state(), it is better to add
it to fec_ptp_restore_state(). However, considering that this is
not related to the current problem, and there are relatively few
calls to fec_ptp_restore_state(), I did not do this. If there are more
calls to fec_ptp_restore_state()/fec_ptp_restore_state() in the
future, I will consider it.

Thanks.

> >
> > /* Whack a reset. We should wait for this.
> > * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
> > @@ -1340,7 +1341,8 @@ fec_stop(struct net_device *ndev)
> > netdev_err(ndev, "Graceful transmit stop did not complete!\n");
> > }
> >
> > - fec_ptp_save_state(fep);
> > + if (fep->bufdesc_ex)
> > + fec_ptp_save_state(fep);
> >
> > /* Whack a reset. We should wait for this.
> > * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
> > --
> > 2.34.1
> >
> >