public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: ethernet: ti: cpsw-phy-sel: check bus_find_device() ret value
@ 2018-05-15 23:01 Grygorii Strashko
  2018-05-15 23:07 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Grygorii Strashko @ 2018-05-15 23:01 UTC (permalink / raw)
  To: David S. Miller, netdev
  Cc: Sekhar Nori, linux-kernel, linux-omap, Grygorii Strashko

This fixes klockworks warnings: Pointer 'dev' returned from call to
function 'bus_find_device' at line 179 may be NULL and will be dereferenced
at line 181.

    cpsw-phy-sel.c:179: 'dev' is assigned the return value from function 'bus_find_device'.
    bus.c:342: 'bus_find_device' explicitly returns a NULL value.
    cpsw-phy-sel.c:181: 'dev' is dereferenced by passing argument 1 to function 'dev_get_drvdata'.
    device.h:1024: 'dev' is passed to function 'dev_get_drvdata'.
    device.h:1026: 'dev' is explicitly dereferenced.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
[nsekhar@ti.com: add an error message, fix return path]
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
---
it present for a very long time, so not critical.

 drivers/net/ethernet/ti/cpsw-phy-sel.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ti/cpsw-phy-sel.c b/drivers/net/ethernet/ti/cpsw-phy-sel.c
index 1801364..005fd53 100644
--- a/drivers/net/ethernet/ti/cpsw-phy-sel.c
+++ b/drivers/net/ethernet/ti/cpsw-phy-sel.c
@@ -177,12 +177,19 @@ void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave)
 	}
 
 	dev = bus_find_device(&platform_bus_type, NULL, node, match);
-	of_node_put(node);
+	if (!dev) {
+		dev_err(dev, "unable to find platform device for %s\n",
+			of_node_full_name(node));
+		goto out;
+	}
+
 	priv = dev_get_drvdata(dev);
 
 	priv->cpsw_phy_sel(priv, phy_mode, slave);
 
 	put_device(dev);
+out:
+	of_node_put(node);
 }
 EXPORT_SYMBOL_GPL(cpsw_phy_sel);
 
-- 
2.10.5

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

* Re: [PATCH net-next] net: ethernet: ti: cpsw-phy-sel: check bus_find_device() ret value
  2018-05-15 23:01 [PATCH net-next] net: ethernet: ti: cpsw-phy-sel: check bus_find_device() ret value Grygorii Strashko
@ 2018-05-15 23:07 ` Andy Shevchenko
  2018-05-15 23:11   ` Grygorii Strashko
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2018-05-15 23:07 UTC (permalink / raw)
  To: Grygorii Strashko
  Cc: David S. Miller, netdev, Sekhar Nori, Linux Kernel Mailing List,
	Linux OMAP Mailing List

On Wed, May 16, 2018 at 2:01 AM, Grygorii Strashko
<grygorii.strashko@ti.com> wrote:
> This fixes klockworks warnings: Pointer 'dev' returned from call to
> function 'bus_find_device' at line 179 may be NULL and will be dereferenced
> at line 181.

> +               dev_err(dev, "unable to find platform device for %s\n",
> +                       of_node_full_name(node));

Sorry, isn't %pOF works for this?

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH net-next] net: ethernet: ti: cpsw-phy-sel: check bus_find_device() ret value
  2018-05-15 23:07 ` Andy Shevchenko
@ 2018-05-15 23:11   ` Grygorii Strashko
  0 siblings, 0 replies; 3+ messages in thread
From: Grygorii Strashko @ 2018-05-15 23:11 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: David S. Miller, netdev, Sekhar Nori, Linux Kernel Mailing List,
	Linux OMAP Mailing List



On 05/15/2018 06:07 PM, Andy Shevchenko wrote:
> On Wed, May 16, 2018 at 2:01 AM, Grygorii Strashko
> <grygorii.strashko@ti.com> wrote:
>> This fixes klockworks warnings: Pointer 'dev' returned from call to
>> function 'bus_find_device' at line 179 may be NULL and will be dereferenced
>> at line 181.
> 
>> +               dev_err(dev, "unable to find platform device for %s\n",
>> +                       of_node_full_name(node));
> 
> Sorry, isn't %pOF works for this?
> 

Thanks, will update.

-- 
regards,
-grygorii

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

end of thread, other threads:[~2018-05-15 23:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-15 23:01 [PATCH net-next] net: ethernet: ti: cpsw-phy-sel: check bus_find_device() ret value Grygorii Strashko
2018-05-15 23:07 ` Andy Shevchenko
2018-05-15 23:11   ` Grygorii Strashko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox