All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: phy: Fix verification of EEE support in phy_init_eee
@ 2015-02-17 17:36 Guenter Roeck
  2015-02-18 19:01 ` Florian Fainelli
  2015-02-20 20:30 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Guenter Roeck @ 2015-02-17 17:36 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: netdev, Guenter Roeck, Giuseppe Cavallaro

phy_init_eee uses phy_find_setting(phydev->speed, phydev->duplex)
to find a valid entry in the settings array for the given speed
and duplex value. For full duplex 1000baseT, this will return
the first matching entry, which is the entry for 1000baseKX_Full.

If the phy eee does not support 1000baseKX_Full, this entry will not
match, causing phy_init_eee to fail for no good reason.

Fixes: 9a9c56cb34e6 ("net: phy: fix a bug when verify the EEE support")
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
I have another version where phy_check_valid() is open coded. It looks a bit
messy to me, but I don't really mind either way if that is preferred.

 drivers/net/phy/phy.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index cdcac6a..52cd8db 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -236,6 +236,25 @@ static inline unsigned int phy_find_valid(unsigned int idx, u32 features)
 }
 
 /**
+ * phy_check_valid - check if there is a valid PHY setting which matches
+ *		     speed, duplex, and feature mask
+ * @speed: speed to match
+ * @duplex: duplex to match
+ * @features: A mask of the valid settings
+ *
+ * Description: Returns true if there is a valid setting, false otherwise.
+ */
+static inline bool phy_check_valid(int speed, int duplex, u32 features)
+{
+	unsigned int idx;
+
+	idx = phy_find_valid(phy_find_setting(speed, duplex), features);
+
+	return settings[idx].speed == speed && settings[idx].duplex == duplex &&
+		(settings[idx].setting & features);
+}
+
+/**
  * phy_sanitize_settings - make sure the PHY is set to supported speed and duplex
  * @phydev: the target phy_device struct
  *
@@ -1045,7 +1064,6 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
 		int eee_lp, eee_cap, eee_adv;
 		u32 lp, cap, adv;
 		int status;
-		unsigned int idx;
 
 		/* Read phy status to properly get the right settings */
 		status = phy_read_status(phydev);
@@ -1077,8 +1095,7 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
 
 		adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
 		lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
-		idx = phy_find_setting(phydev->speed, phydev->duplex);
-		if (!(lp & adv & settings[idx].setting))
+		if (!phy_check_valid(phydev->speed, phydev->duplex, lp & adv))
 			goto eee_exit_err;
 
 		if (clk_stop_enable) {
-- 
2.1.0

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

* Re: [PATCH] net: phy: Fix verification of EEE support in phy_init_eee
  2015-02-17 17:36 [PATCH] net: phy: Fix verification of EEE support in phy_init_eee Guenter Roeck
@ 2015-02-18 19:01 ` Florian Fainelli
  2015-02-20 20:30 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2015-02-18 19:01 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: netdev, Giuseppe Cavallaro

On 17/02/15 09:36, Guenter Roeck wrote:
> phy_init_eee uses phy_find_setting(phydev->speed, phydev->duplex)
> to find a valid entry in the settings array for the given speed
> and duplex value. For full duplex 1000baseT, this will return
> the first matching entry, which is the entry for 1000baseKX_Full.
> 
> If the phy eee does not support 1000baseKX_Full, this entry will not
> match, causing phy_init_eee to fail for no good reason.
> 
> Fixes: 9a9c56cb34e6 ("net: phy: fix a bug when verify the EEE support")
> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Fixes: 3e7077067e80c ("phy: Expand phy speed/duplex settings array")

> ---
> I have another version where phy_check_valid() is open coded. It looks a bit
> messy to me, but I don't really mind either way if that is preferred.
> 
>  drivers/net/phy/phy.c | 23 ++++++++++++++++++++---
>  1 file changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index cdcac6a..52cd8db 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -236,6 +236,25 @@ static inline unsigned int phy_find_valid(unsigned int idx, u32 features)
>  }
>  
>  /**
> + * phy_check_valid - check if there is a valid PHY setting which matches
> + *		     speed, duplex, and feature mask
> + * @speed: speed to match
> + * @duplex: duplex to match
> + * @features: A mask of the valid settings
> + *
> + * Description: Returns true if there is a valid setting, false otherwise.
> + */
> +static inline bool phy_check_valid(int speed, int duplex, u32 features)
> +{
> +	unsigned int idx;
> +
> +	idx = phy_find_valid(phy_find_setting(speed, duplex), features);
> +
> +	return settings[idx].speed == speed && settings[idx].duplex == duplex &&
> +		(settings[idx].setting & features);
> +}
> +
> +/**
>   * phy_sanitize_settings - make sure the PHY is set to supported speed and duplex
>   * @phydev: the target phy_device struct
>   *
> @@ -1045,7 +1064,6 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
>  		int eee_lp, eee_cap, eee_adv;
>  		u32 lp, cap, adv;
>  		int status;
> -		unsigned int idx;
>  
>  		/* Read phy status to properly get the right settings */
>  		status = phy_read_status(phydev);
> @@ -1077,8 +1095,7 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
>  
>  		adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
>  		lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
> -		idx = phy_find_setting(phydev->speed, phydev->duplex);
> -		if (!(lp & adv & settings[idx].setting))
> +		if (!phy_check_valid(phydev->speed, phydev->duplex, lp & adv))
>  			goto eee_exit_err;
>  
>  		if (clk_stop_enable) {
> 


-- 
Florian

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

* Re: [PATCH] net: phy: Fix verification of EEE support in phy_init_eee
  2015-02-17 17:36 [PATCH] net: phy: Fix verification of EEE support in phy_init_eee Guenter Roeck
  2015-02-18 19:01 ` Florian Fainelli
@ 2015-02-20 20:30 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-02-20 20:30 UTC (permalink / raw)
  To: linux; +Cc: f.fainelli, netdev, peppe.cavallaro

From: Guenter Roeck <linux@roeck-us.net>
Date: Tue, 17 Feb 2015 09:36:22 -0800

> phy_init_eee uses phy_find_setting(phydev->speed, phydev->duplex)
> to find a valid entry in the settings array for the given speed
> and duplex value. For full duplex 1000baseT, this will return
> the first matching entry, which is the entry for 1000baseKX_Full.
> 
> If the phy eee does not support 1000baseKX_Full, this entry will not
> match, causing phy_init_eee to fail for no good reason.
> 
> Fixes: 9a9c56cb34e6 ("net: phy: fix a bug when verify the EEE support")
> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Applied, and queued up for -stable, thanks.

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

end of thread, other threads:[~2015-02-20 20: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 17:36 [PATCH] net: phy: Fix verification of EEE support in phy_init_eee Guenter Roeck
2015-02-18 19:01 ` Florian Fainelli
2015-02-20 20:30 ` 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.