* [PATCH] net: dsa: Set valid phy interface type
@ 2015-02-17 5:23 Guenter Roeck
2015-02-17 17:04 ` Florian Fainelli
2015-02-17 18:37 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Guenter Roeck @ 2015-02-17 5:23 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, Guenter Roeck, Florian Fainelli, Andrew Lunn
If the phy interface mode is not found in devicetree, or if devicetree
is not configured, of_get_phy_mode returns -ENODEV. The current code
sets the phy interface mode to the return value from of_get_phy_mode
without checking if it is valid.
This invalid phy interface mode is passed as parameter to of_phy_connect
or to phy_connect_direct. This sets the phy interface mode to the invalid
value, which in turn causes problems for any code using phydev->interface.
Fixes: b31f65fb4383 ("net: dsa: slave: Fix autoneg for phys on switch MDIO bus")
Fixes: 0d8bcdd383b8 ("net: dsa: allow for more complex PHY setups")
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
net/dsa/slave.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index d104ae1..f23dead 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -521,10 +521,13 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
struct device_node *phy_dn, *port_dn;
bool phy_is_fixed = false;
u32 phy_flags = 0;
- int ret;
+ int mode, ret;
port_dn = cd->port_dn[p->port];
- p->phy_interface = of_get_phy_mode(port_dn);
+ mode = of_get_phy_mode(port_dn);
+ if (mode < 0)
+ mode = PHY_INTERFACE_MODE_NA;
+ p->phy_interface = mode;
phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
if (of_phy_is_fixed_link(port_dn)) {
@@ -559,6 +562,8 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
if (!p->phy)
return -ENODEV;
+ /* Use already configured phy mode */
+ p->phy_interface = p->phy->interface;
phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
p->phy_interface);
} else {
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: dsa: Set valid phy interface type
2015-02-17 5:23 [PATCH] net: dsa: Set valid phy interface type Guenter Roeck
@ 2015-02-17 17:04 ` Florian Fainelli
2015-02-17 18:37 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2015-02-17 17:04 UTC (permalink / raw)
To: Guenter Roeck, David S. Miller; +Cc: netdev, Andrew Lunn
On 16/02/15 21:23, Guenter Roeck wrote:
> If the phy interface mode is not found in devicetree, or if devicetree
> is not configured, of_get_phy_mode returns -ENODEV. The current code
> sets the phy interface mode to the return value from of_get_phy_mode
> without checking if it is valid.
>
> This invalid phy interface mode is passed as parameter to of_phy_connect
> or to phy_connect_direct. This sets the phy interface mode to the invalid
> value, which in turn causes problems for any code using phydev->interface.
>
> Fixes: b31f65fb4383 ("net: dsa: slave: Fix autoneg for phys on switch MDIO bus")
> Fixes: 0d8bcdd383b8 ("net: dsa: allow for more complex PHY setups")
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
This is 'net' material since you are fixing a bug here, thanks!
> ---
> net/dsa/slave.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/net/dsa/slave.c b/net/dsa/slave.c
> index d104ae1..f23dead 100644
> --- a/net/dsa/slave.c
> +++ b/net/dsa/slave.c
> @@ -521,10 +521,13 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
> struct device_node *phy_dn, *port_dn;
> bool phy_is_fixed = false;
> u32 phy_flags = 0;
> - int ret;
> + int mode, ret;
>
> port_dn = cd->port_dn[p->port];
> - p->phy_interface = of_get_phy_mode(port_dn);
> + mode = of_get_phy_mode(port_dn);
> + if (mode < 0)
> + mode = PHY_INTERFACE_MODE_NA;
> + p->phy_interface = mode;
>
> phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
> if (of_phy_is_fixed_link(port_dn)) {
> @@ -559,6 +562,8 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
> if (!p->phy)
> return -ENODEV;
>
> + /* Use already configured phy mode */
> + p->phy_interface = p->phy->interface;
> phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
> p->phy_interface);
> } else {
>
--
Florian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: dsa: Set valid phy interface type
2015-02-17 5:23 [PATCH] net: dsa: Set valid phy interface type Guenter Roeck
2015-02-17 17:04 ` Florian Fainelli
@ 2015-02-17 18:37 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-02-17 18:37 UTC (permalink / raw)
To: linux; +Cc: netdev, f.fainelli, andrew
From: Guenter Roeck <linux@roeck-us.net>
Date: Mon, 16 Feb 2015 21:23:51 -0800
> If the phy interface mode is not found in devicetree, or if devicetree
> is not configured, of_get_phy_mode returns -ENODEV. The current code
> sets the phy interface mode to the return value from of_get_phy_mode
> without checking if it is valid.
>
> This invalid phy interface mode is passed as parameter to of_phy_connect
> or to phy_connect_direct. This sets the phy interface mode to the invalid
> value, which in turn causes problems for any code using phydev->interface.
>
> Fixes: b31f65fb4383 ("net: dsa: slave: Fix autoneg for phys on switch MDIO bus")
> Fixes: 0d8bcdd383b8 ("net: dsa: allow for more complex PHY setups")
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-02-17 18:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-17 5:23 [PATCH] net: dsa: Set valid phy interface type Guenter Roeck
2015-02-17 17:04 ` Florian Fainelli
2015-02-17 18:37 ` 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.