[PATCH net 1/2] net: fec_ptp: add clock rate zero check

Russell King (Oracle) linux at armlinux.org.uk
Wed Jun 16 03:20:38 PDT 2021


On Wed, Jun 16, 2021 at 05:14:25PM +0800, Joakim Zhang wrote:
> From: Fugang Duan <fugang.duan at nxp.com>
> 
> Add clock rate zero check to fix coverity issue of "divide by 0".
> 
> Fixes: commit 85bd1798b24a ("net: fec: fix spin_lock dead lock")
> Signed-off-by: Fugang Duan <fugang.duan at nxp.com>
> Signed-off-by: Joakim Zhang <qiangqing.zhang at nxp.com>
> ---
>  drivers/net/ethernet/freescale/fec_ptp.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
> index 1753807cbf97..7326a0612823 100644
> --- a/drivers/net/ethernet/freescale/fec_ptp.c
> +++ b/drivers/net/ethernet/freescale/fec_ptp.c
> @@ -604,6 +604,10 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx)
>  	fep->ptp_caps.enable = fec_ptp_enable;
>  
>  	fep->cycle_speed = clk_get_rate(fep->clk_ptp);
> +	if (!fep->cycle_speed) {
> +		fep->cycle_speed = NSEC_PER_SEC;
> +		dev_err(&fep->pdev->dev, "clk_ptp clock rate is zero\n");

If this is supposed to be an error message, it doesn't convey that
something is really wrong to the user. Maybe something like this would
be more meaningful to the user:

	"PTP clock rate should not be zero, using 1GHz instead. PTP
	clock may be unreliable.\n"

It may be appropriate not to publish PTP support for the interface if
we don't have a valid clock rate, which is probably the safer approach
and would probably make the problem more noticable to the end user so
it gets fixed.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!



More information about the linux-arm-kernel mailing list