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

From: Simon Horman <[email-masked]>
Date: Wed, 9 Oct 2024 12:54:48 +0100

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 <[email-masked]>
> Closes: https://lore.kernel.org/lkml/[email-masked]/
> Signed-off-by: Wei Fang <[email-masked]>
> ---
>  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.

>  
>  	/* 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
> 
>