* [RFC PATCH] net: macb: Add null check for PCLK and HCLK
@ 2019-03-19 5:54 Harini Katakam
2019-03-19 16:21 ` Claudiu.Beznea
0 siblings, 1 reply; 3+ messages in thread
From: Harini Katakam @ 2019-03-19 5:54 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>
---
drivers/net/ethernet/cadence/macb_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index ad099fd..d12d815 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3370,13 +3370,13 @@ 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(*pclk) || (*pclk == NULL)) {
err = PTR_ERR(*pclk);
dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err);
return err;
}
- if (IS_ERR(*hclk)) {
+ if (IS_ERR(*hclk) || (*hclk == NULL)) {
err = PTR_ERR(*hclk);
dev_err(&pdev->dev, "failed to get hclk (%u)\n", err);
return err;
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC PATCH] net: macb: Add null check for PCLK and HCLK
2019-03-19 5:54 [RFC PATCH] net: macb: Add null check for PCLK and HCLK Harini Katakam
@ 2019-03-19 16:21 ` Claudiu.Beznea
2019-03-20 10:46 ` Harini Katakam
0 siblings, 1 reply; 3+ messages in thread
From: Claudiu.Beznea @ 2019-03-19 16:21 UTC (permalink / raw)
To: harini.katakam, Nicolas.Ferre, davem
Cc: netdev, linux-kernel, michal.simek, harinikatakamlinux
On 19.03.2019 07:54, Harini Katakam wrote:
> 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>
> ---
> drivers/net/ethernet/cadence/macb_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index ad099fd..d12d815 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -3370,13 +3370,13 @@ 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(*pclk) || (*pclk == NULL)) {
You can use IS_ERR_OR_NULL() macro.
> err = PTR_ERR(*pclk);
> dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err);
> return err;
> }
>
> - if (IS_ERR(*hclk)) {
> + if (IS_ERR(*hclk) || (*hclk == NULL)) {
Ditto
> err = PTR_ERR(*hclk);
> dev_err(&pdev->dev, "failed to get hclk (%u)\n", err);
> return err;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC PATCH] net: macb: Add null check for PCLK and HCLK
2019-03-19 16:21 ` Claudiu.Beznea
@ 2019-03-20 10:46 ` Harini Katakam
0 siblings, 0 replies; 3+ messages in thread
From: Harini Katakam @ 2019-03-20 10:46 UTC (permalink / raw)
To: Claudiu Beznea
Cc: Harini Katakam, Nicolas Ferre, David Miller, netdev,
linux-kernel, Michal Simek
Hi Claudiu,
On Tue, Mar 19, 2019 at 9:51 PM <Claudiu.Beznea@microchip.com> wrote:
>
>
>
> On 19.03.2019 07:54, Harini Katakam wrote:
<snip>
> > - if (IS_ERR(*pclk)) {
> > + if (IS_ERR(*pclk) || (*pclk == NULL)) {
>
> You can use IS_ERR_OR_NULL() macro.
>
Yes will fix, thanks.
Also the error code from this function will end up being 0 below
even if pointer is NULL. Will fix that.
Regards,
Harini
> > err = PTR_ERR(*pclk);
> > dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err);
> > return err;
> > }
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-03-20 10:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 5:54 [RFC PATCH] net: macb: Add null check for PCLK and HCLK Harini Katakam
2019-03-19 16:21 ` Claudiu.Beznea
2019-03-20 10:46 ` Harini Katakam
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).