All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] of: of_mdio: Ensure mdio device is a PHY
@ 2016-01-26 14:12 Andrew Lunn
  2016-01-26 16:36 ` Aaro Koskinen
  2016-01-29  0:08 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Lunn @ 2016-01-26 14:12 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, aaro.koskinen, olof, Andrew Lunn

of_phy_find_device() is used to find the phy device associated with a
device node. It is expected the node is for a PHY device, but in fact
it could of been probed as a generic MDIO device. Ensure the device is
a PHY before returning it.

Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")
Reported-by: Aaro Koskinen <aaro.koskinen@nokia.com>
Reported-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---

This is only 1/2 the fix. It will stop the NULL pointer dereference in
the mutex code, but the Ethernet device probe is likely to return an
error when it cannot find its PHY.
---
 drivers/of/of_mdio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 86829f8064a6..b5aa004a24b6 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -256,11 +256,19 @@ static int of_phy_match(struct device *dev, void *phy_np)
 struct phy_device *of_phy_find_device(struct device_node *phy_np)
 {
 	struct device *d;
+	struct mdio_device *mdiodev;
+
 	if (!phy_np)
 		return NULL;
 
 	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
-	return d ? to_phy_device(d) : NULL;
+	if (d) {
+		mdiodev = to_mdio_device(d);
+		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
+			return to_phy_device(d);
+	}
+
+	return NULL;
 }
 EXPORT_SYMBOL(of_phy_find_device);
 
-- 
2.7.0

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

* Re: [PATCH net] of: of_mdio: Ensure mdio device is a PHY
  2016-01-26 14:12 [PATCH net] of: of_mdio: Ensure mdio device is a PHY Andrew Lunn
@ 2016-01-26 16:36 ` Aaro Koskinen
  2016-01-29  0:08 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Aaro Koskinen @ 2016-01-26 16:36 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: David Miller, netdev, Florian Fainelli, olof

Hi,

On Tue, Jan 26, 2016 at 03:12:30PM +0100, Andrew Lunn wrote:
> of_phy_find_device() is used to find the phy device associated with a
> device node. It is expected the node is for a PHY device, but in fact
> it could of been probed as a generic MDIO device. Ensure the device is
> a PHY before returning it.
> 
> Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")
> Reported-by: Aaro Koskinen <aaro.koskinen@nokia.com>
> Reported-by: Olof Johansson <olof@lixom.net>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

This fixes the crash for me, so:

Tested-by: Aaro Koskinen <aaro.koskinen@nokia.com>

> ---
> 
> This is only 1/2 the fix. It will stop the NULL pointer dereference in
> the mutex code, but the Ethernet device probe is likely to return an
> error when it cannot find its PHY.

Yes, it's still not possible to actually use mgmt0:

$ ifconfig mgmt0 up
[   74.432849] octeon_mgmt 1070000100000.ethernet: Cannot initialize PHY on MIX0

A.

> ---
>  drivers/of/of_mdio.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 86829f8064a6..b5aa004a24b6 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -256,11 +256,19 @@ static int of_phy_match(struct device *dev, void *phy_np)
>  struct phy_device *of_phy_find_device(struct device_node *phy_np)
>  {
>  	struct device *d;
> +	struct mdio_device *mdiodev;
> +
>  	if (!phy_np)
>  		return NULL;
>  
>  	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
> -	return d ? to_phy_device(d) : NULL;
> +	if (d) {
> +		mdiodev = to_mdio_device(d);
> +		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
> +			return to_phy_device(d);
> +	}
> +
> +	return NULL;
>  }
>  EXPORT_SYMBOL(of_phy_find_device);
>  
> -- 
> 2.7.0
> 

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

* Re: [PATCH net] of: of_mdio: Ensure mdio device is a PHY
  2016-01-26 14:12 [PATCH net] of: of_mdio: Ensure mdio device is a PHY Andrew Lunn
  2016-01-26 16:36 ` Aaro Koskinen
@ 2016-01-29  0:08 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-01-29  0:08 UTC (permalink / raw)
  To: andrew; +Cc: netdev, f.fainelli, aaro.koskinen, olof

From: Andrew Lunn <andrew@lunn.ch>
Date: Tue, 26 Jan 2016 15:12:30 +0100

> of_phy_find_device() is used to find the phy device associated with a
> device node. It is expected the node is for a PHY device, but in fact
> it could of been probed as a generic MDIO device. Ensure the device is
> a PHY before returning it.
> 
> Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")
> Reported-by: Aaro Koskinen <aaro.koskinen@nokia.com>
> Reported-by: Olof Johansson <olof@lixom.net>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Applied.

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

end of thread, other threads:[~2016-01-29  0:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-26 14:12 [PATCH net] of: of_mdio: Ensure mdio device is a PHY Andrew Lunn
2016-01-26 16:36 ` Aaro Koskinen
2016-01-29  0:08 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.