Commit 4ae6e50c authored by Bjorn Helgaas's avatar Bjorn Helgaas Committed by David S. Miller

phy: fix compiler array bounds warning on settings[]

With -Werror=array-bounds, gcc v4.7.x warns that in phy_find_valid(), the
settings[] "array subscript is above array bounds", I think because idx is
a signed integer and if the caller supplied idx < 0, we pass the guard but
still reference out of bounds.

Fix this by making idx unsigned here and elsewhere.
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e588e2f2
...@@ -164,9 +164,9 @@ static const struct phy_setting settings[] = { ...@@ -164,9 +164,9 @@ static const struct phy_setting settings[] = {
* of that setting. Returns the index of the last setting if * of that setting. Returns the index of the last setting if
* none of the others match. * none of the others match.
*/ */
static inline int phy_find_setting(int speed, int duplex) static inline unsigned int phy_find_setting(int speed, int duplex)
{ {
int idx = 0; unsigned int idx = 0;
while (idx < ARRAY_SIZE(settings) && while (idx < ARRAY_SIZE(settings) &&
(settings[idx].speed != speed || settings[idx].duplex != duplex)) (settings[idx].speed != speed || settings[idx].duplex != duplex))
...@@ -185,7 +185,7 @@ static inline int phy_find_setting(int speed, int duplex) ...@@ -185,7 +185,7 @@ static inline int phy_find_setting(int speed, int duplex)
* the mask in features. Returns the index of the last setting * the mask in features. Returns the index of the last setting
* if nothing else matches. * if nothing else matches.
*/ */
static inline int phy_find_valid(int idx, u32 features) static inline unsigned int phy_find_valid(unsigned int idx, u32 features)
{ {
while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features))
idx++; idx++;
...@@ -204,7 +204,7 @@ static inline int phy_find_valid(int idx, u32 features) ...@@ -204,7 +204,7 @@ static inline int phy_find_valid(int idx, u32 features)
static void phy_sanitize_settings(struct phy_device *phydev) static void phy_sanitize_settings(struct phy_device *phydev)
{ {
u32 features = phydev->supported; u32 features = phydev->supported;
int idx; unsigned int idx;
/* Sanitize settings based on PHY capabilities */ /* Sanitize settings based on PHY capabilities */
if ((features & SUPPORTED_Autoneg) == 0) if ((features & SUPPORTED_Autoneg) == 0)
...@@ -954,7 +954,8 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) ...@@ -954,7 +954,8 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
(phydev->interface == PHY_INTERFACE_MODE_RGMII))) { (phydev->interface == PHY_INTERFACE_MODE_RGMII))) {
int eee_lp, eee_cap, eee_adv; int eee_lp, eee_cap, eee_adv;
u32 lp, cap, adv; u32 lp, cap, adv;
int idx, status; int status;
unsigned int idx;
/* Read phy status to properly get the right settings */ /* Read phy status to properly get the right settings */
status = phy_read_status(phydev); status = phy_read_status(phydev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment