netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: macb: Add null check for PCLK and HCLK
@ 2019-03-20 13:42 Harini Katakam
  2019-03-21 20:22 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Harini Katakam @ 2019-03-20 13:42 UTC (permalink / raw)
  To: nicolas.ferre, davem
  Cc: netdev, linux-kernel, michal.simek, harinikatakamlinux, harini.katakam

Both PCLK and HCLK are "required" clocks according to macb devicetree
documentation. There is a chance that devm_clk_get doesn't return a
negative error but just a NULL clock structure instead. In such a case
the driver proceeds as usual and uses pclk value 0 to calculate MDC
divisor which is incorrect. Hence fix the same in clock initialization.

Signed-off-by: Harini Katakam <harini.katakam@xilinx.com>
---
Changes from RFC:
Use IS_ERR_OR_NULL
Add error for NULL condition

 drivers/net/ethernet/cadence/macb_main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 98c2352..a44171f 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3370,14 +3370,20 @@ static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
 		*hclk = devm_clk_get(&pdev->dev, "hclk");
 	}
 
-	if (IS_ERR(*pclk)) {
+	if (IS_ERR_OR_NULL(*pclk)) {
 		err = PTR_ERR(*pclk);
+		if (!err)
+			err = -ENODEV;
+
 		dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err);
 		return err;
 	}
 
-	if (IS_ERR(*hclk)) {
+	if (IS_ERR_OR_NULL(*hclk)) {
 		err = PTR_ERR(*hclk);
+		if (!err)
+			err = -ENODEV;
+
 		dev_err(&pdev->dev, "failed to get hclk (%u)\n", err);
 		return err;
 	}
-- 
2.7.4


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

* Re: [PATCH] net: macb: Add null check for PCLK and HCLK
  2019-03-20 13:42 [PATCH] net: macb: Add null check for PCLK and HCLK Harini Katakam
@ 2019-03-21 20:22 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-03-21 20:22 UTC (permalink / raw)
  To: harini.katakam
  Cc: nicolas.ferre, netdev, linux-kernel, michal.simek, harinikatakamlinux

From: Harini Katakam <harini.katakam@xilinx.com>
Date: Wed, 20 Mar 2019 19:12:22 +0530

> Both PCLK and HCLK are "required" clocks according to macb devicetree
> documentation. There is a chance that devm_clk_get doesn't return a
> negative error but just a NULL clock structure instead. In such a case
> the driver proceeds as usual and uses pclk value 0 to calculate MDC
> divisor which is incorrect. Hence fix the same in clock initialization.
> 
> Signed-off-by: Harini Katakam <harini.katakam@xilinx.com>

Applied, thanks.

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

end of thread, other threads:[~2019-03-21 20:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20 13:42 [PATCH] net: macb: Add null check for PCLK and HCLK Harini Katakam
2019-03-21 20:22 ` David Miller

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