Skip to content

Commit

Permalink
net: macb: Add null check for PCLK and HCLK
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
harini-katakam authored and davem330 committed Mar 21, 2019
1 parent 06acc17 commit cd5afa9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/net/ethernet/cadence/macb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit cd5afa9

Please sign in to comment.