linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] net: fixes for fec ptp
@ 2021-06-16  9:14 Joakim Zhang
  2021-06-16  9:14 ` [PATCH net 1/2] net: fec_ptp: add clock rate zero check Joakim Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Joakim Zhang @ 2021-06-16  9:14 UTC (permalink / raw)
  To: davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu, mcoquelin.stm32
  Cc: netdev, linux-kernel, linux-stm32, linux-arm-kernel, linux-imx

Small fixes for fec ptp.

Fugang Duan (1):
  net: fec_ptp: add clock rate zero check

Joakim Zhang (1):
  net: fec_ptp: fix issue caused by refactor the fec_devtype

 drivers/net/ethernet/freescale/fec_ptp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net 1/2] net: fec_ptp: add clock rate zero check
  2021-06-16  9:14 [PATCH net 0/2] net: fixes for fec ptp Joakim Zhang
@ 2021-06-16  9:14 ` Joakim Zhang
  2021-06-16 10:20   ` Russell King (Oracle)
  2021-06-16  9:14 ` [PATCH net 2/2] net: fec_ptp: fix issue caused by refactor the fec_devtype Joakim Zhang
  2021-06-16 19:50 ` [PATCH net 0/2] net: fixes for fec ptp patchwork-bot+netdevbpf
  2 siblings, 1 reply; 7+ messages in thread
From: Joakim Zhang @ 2021-06-16  9:14 UTC (permalink / raw)
  To: davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu, mcoquelin.stm32
  Cc: netdev, linux-kernel, linux-stm32, linux-arm-kernel, linux-imx

From: Fugang Duan <fugang.duan@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@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@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");
+	}
 	fep->ptp_inc = NSEC_PER_SEC / fep->cycle_speed;
 
 	spin_lock_init(&fep->tmreg_lock);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net 2/2] net: fec_ptp: fix issue caused by refactor the fec_devtype
  2021-06-16  9:14 [PATCH net 0/2] net: fixes for fec ptp Joakim Zhang
  2021-06-16  9:14 ` [PATCH net 1/2] net: fec_ptp: add clock rate zero check Joakim Zhang
@ 2021-06-16  9:14 ` Joakim Zhang
  2021-06-16 19:50 ` [PATCH net 0/2] net: fixes for fec ptp patchwork-bot+netdevbpf
  2 siblings, 0 replies; 7+ messages in thread
From: Joakim Zhang @ 2021-06-16  9:14 UTC (permalink / raw)
  To: davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu, mcoquelin.stm32
  Cc: netdev, linux-kernel, linux-stm32, linux-arm-kernel, linux-imx

Commit da722186f654 ("net: fec: set GPR bit on suspend by DT configuration.")
refactor the fec_devtype, need adjust ptp driver accordingly.

Fixes: da722186f654 ("net: fec: set GPR bit on suspend by DT configuration.")
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
 drivers/net/ethernet/freescale/fec_ptp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 7326a0612823..d71eac7e1924 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -215,15 +215,13 @@ static u64 fec_ptp_read(const struct cyclecounter *cc)
 {
 	struct fec_enet_private *fep =
 		container_of(cc, struct fec_enet_private, cc);
-	const struct platform_device_id *id_entry =
-		platform_get_device_id(fep->pdev);
 	u32 tempval;
 
 	tempval = readl(fep->hwp + FEC_ATIME_CTRL);
 	tempval |= FEC_T_CTRL_CAPTURE;
 	writel(tempval, fep->hwp + FEC_ATIME_CTRL);
 
-	if (id_entry->driver_data & FEC_QUIRK_BUG_CAPTURE)
+	if (fep->quirks & FEC_QUIRK_BUG_CAPTURE)
 		udelay(1);
 
 	return readl(fep->hwp + FEC_ATIME);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net 1/2] net: fec_ptp: add clock rate zero check
  2021-06-16  9:14 ` [PATCH net 1/2] net: fec_ptp: add clock rate zero check Joakim Zhang
@ 2021-06-16 10:20   ` Russell King (Oracle)
  2021-06-16 11:40     ` Joakim Zhang
  0 siblings, 1 reply; 7+ messages in thread
From: Russell King (Oracle) @ 2021-06-16 10:20 UTC (permalink / raw)
  To: Joakim Zhang
  Cc: davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, netdev, linux-kernel, linux-stm32,
	linux-arm-kernel, linux-imx

On Wed, Jun 16, 2021 at 05:14:25PM +0800, Joakim Zhang wrote:
> From: Fugang Duan <fugang.duan@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@nxp.com>
> Signed-off-by: Joakim Zhang <qiangqing.zhang@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!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH net 1/2] net: fec_ptp: add clock rate zero check
  2021-06-16 10:20   ` Russell King (Oracle)
@ 2021-06-16 11:40     ` Joakim Zhang
  2021-06-16 13:28       ` Russell King (Oracle)
  0 siblings, 1 reply; 7+ messages in thread
From: Joakim Zhang @ 2021-06-16 11:40 UTC (permalink / raw)
  To: Russell King
  Cc: davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, netdev, linux-kernel, linux-stm32,
	linux-arm-kernel, dl-linux-imx


Hi Russell,

> -----Original Message-----
> From: Russell King <linux@armlinux.org.uk>
> Sent: 2021年6月16日 18:21
> To: Joakim Zhang <qiangqing.zhang@nxp.com>
> Cc: davem@davemloft.net; kuba@kernel.org; peppe.cavallaro@st.com;
> alexandre.torgue@foss.st.com; joabreu@synopsys.com;
> mcoquelin.stm32@gmail.com; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org; linux-stm32@st-md-mailman.stormreply.com;
> linux-arm-kernel@lists.infradead.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH net 1/2] net: fec_ptp: add clock rate zero check
> 
> On Wed, Jun 16, 2021 at 05:14:25PM +0800, Joakim Zhang wrote:
> > From: Fugang Duan <fugang.duan@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@nxp.com>
> > Signed-off-by: Joakim Zhang <qiangqing.zhang@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"
Make Sense.

> 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.

Do you mean that print an error message then return directly? It seems better.

if (!fep->cycle_speed) {
	dev_err(&fep->pdev->dev, "PTP clock rate should not be zero!\n");
	return;
}

Best Regards,
Joakim Zhang
> --
> RMK's Patch system:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.ar
> mlinux.org.uk%2Fdeveloper%2Fpatches%2F&amp;data=04%7C01%7Cqiangqin
> g.zhang%40nxp.com%7Cb3c85322e359446e4eee08d930b06701%7C686ea1d3
> bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637594356476903644%7CUnknow
> n%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1ha
> WwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=TH4fZJRu8Ii6w7y05N8CHWoQR
> R9OegsYB7VAwgSpTcU%3D&amp;reserved=0
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net 1/2] net: fec_ptp: add clock rate zero check
  2021-06-16 11:40     ` Joakim Zhang
@ 2021-06-16 13:28       ` Russell King (Oracle)
  0 siblings, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2021-06-16 13:28 UTC (permalink / raw)
  To: Joakim Zhang
  Cc: davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, netdev, linux-kernel, linux-stm32,
	linux-arm-kernel, dl-linux-imx

Hi Joakim,

On Wed, Jun 16, 2021 at 11:40:29AM +0000, Joakim Zhang wrote:
> Do you mean that print an error message then return directly? It seems better.

Nearly - one has to ensure that the cleanup functions don't provoke a
crash though. I notice fec_ptp_stop() makes use of fep->time_keep
and also fep->ptp_clock.

fep->time_keep is initialised after where you need to test for zero
cycle_speed, so the initialisation would need moving earlier.

I would have thought that ftp->ptp_clock should be NULL, so that's
probably okay, but should be checked that this assumption is in fact
true.

> if (!fep->cycle_speed) {
> 	dev_err(&fep->pdev->dev, "PTP clock rate should not be zero!\n");

I'd still say something like "PTP clock rate should not be zero,
disabling PTP" - say what's wrong and what we are doing. Also,
please avoid exclaimation marks in error messages.

Thanks.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net 0/2] net: fixes for fec ptp
  2021-06-16  9:14 [PATCH net 0/2] net: fixes for fec ptp Joakim Zhang
  2021-06-16  9:14 ` [PATCH net 1/2] net: fec_ptp: add clock rate zero check Joakim Zhang
  2021-06-16  9:14 ` [PATCH net 2/2] net: fec_ptp: fix issue caused by refactor the fec_devtype Joakim Zhang
@ 2021-06-16 19:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-06-16 19:50 UTC (permalink / raw)
  To: Joakim Zhang
  Cc: davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, netdev, linux-kernel, linux-stm32,
	linux-arm-kernel, linux-imx

Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Wed, 16 Jun 2021 17:14:24 +0800 you wrote:
> Small fixes for fec ptp.
> 
> Fugang Duan (1):
>   net: fec_ptp: add clock rate zero check
> 
> Joakim Zhang (1):
>   net: fec_ptp: fix issue caused by refactor the fec_devtype
> 
> [...]

Here is the summary with links:
  - [net,1/2] net: fec_ptp: add clock rate zero check
    https://git.kernel.org/netdev/net/c/cb3cefe3f3f8
  - [net,2/2] net: fec_ptp: fix issue caused by refactor the fec_devtype
    https://git.kernel.org/netdev/net/c/d23765646e71

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] 7+ messages in thread

end of thread, other threads:[~2021-06-16 19:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16  9:14 [PATCH net 0/2] net: fixes for fec ptp Joakim Zhang
2021-06-16  9:14 ` [PATCH net 1/2] net: fec_ptp: add clock rate zero check Joakim Zhang
2021-06-16 10:20   ` Russell King (Oracle)
2021-06-16 11:40     ` Joakim Zhang
2021-06-16 13:28       ` Russell King (Oracle)
2021-06-16  9:14 ` [PATCH net 2/2] net: fec_ptp: fix issue caused by refactor the fec_devtype Joakim Zhang
2021-06-16 19:50 ` [PATCH net 0/2] net: fixes for fec ptp 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;
as well as URLs for NNTP newsgroup(s).