summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPallantla Poornima <pallantlax.poornima@intel.com>2019-09-19 12:01:47 +0100
committerFerruh Yigit <ferruh.yigit@intel.com>2019-10-21 10:06:04 +0100
commitd1b274e3b654813ae5bc06ca2e42882a6ab33a05 (patch)
tree5cb03179a7a9dfe113906810bcb635ac4b5e3e50
parent7bef76e5f840b6222c2b6bee6d9a5e54dfe8b167 (diff)
downloaddpdk-next-net-intel-d1b274e3b654813ae5bc06ca2e42882a6ab33a05.zip
dpdk-next-net-intel-d1b274e3b654813ae5bc06ca2e42882a6ab33a05.tar.gz
dpdk-next-net-intel-d1b274e3b654813ae5bc06ca2e42882a6ab33a05.tar.xz
net/axgbe: fix double unlock
One issue caught by Coverity 340835 *unlock: axgbe_phy_set_mode unlocks pdata->phy_mutex *double_unlock: axgbe_phy_sfp_detect unlocks pdata->phy_mutex while it is unlocked. In axgbe_phy_sfp_detect()/axgbe_phy_set_redrv_mode(), axgbe_phy_get_comm_ownership() and axgbe_phy_put_comm_ownership() are invoked subsequently. Currently in axgbe_phy_get_comm_ownership(), during one of the case 'phy_data->comm_owned' is not protected and before returning 0, lock is not called and unlock is called in axgbe_phy_put_comm_ownership() directly which is incorrect. Ideally, the variable 'phy_data->comm_owned' needs to be protected. During success scenario, lock is called in axgbe_phy_get_comm_ownership() followed by unlock in axgbe_phy_put_comm_ownership(). In failure case, unlock is invoked in axgbe_phy_get_comm_ownership() itself appropriately. The fix is to protect 'phy_data->comm_owned' in the identified case ensuring locks/unlocks properly exist. Coverity issue: 340835 Fixes: a5c7273771e8 ("net/axgbe: add phy programming APIs") Cc: stable@dpdk.org Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com> Acked-by: Ravi Kumar <ravi1.kumar@amd.com>
-rw-r--r--drivers/net/axgbe/axgbe_phy_impl.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
index 973177f..2267c5f 100644
--- a/drivers/net/axgbe/axgbe_phy_impl.c
+++ b/drivers/net/axgbe/axgbe_phy_impl.c
@@ -412,15 +412,15 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)
uint64_t timeout;
unsigned int mutex_id;
- if (phy_data->comm_owned)
- return 0;
-
/* The I2C and MDIO/GPIO bus is multiplexed between multiple devices,
* the driver needs to take the software mutex and then the hardware
* mutexes before being able to use the busses.
*/
pthread_mutex_lock(&pdata->phy_mutex);
+ if (phy_data->comm_owned)
+ return 0;
+
/* Clear the mutexes */
XP_IOWRITE(pdata, XP_I2C_MUTEX, AXGBE_MUTEX_RELEASE);
XP_IOWRITE(pdata, XP_MDIO_MUTEX, AXGBE_MUTEX_RELEASE);