Skip to contentSkip to conversation

net/axgbe: fix potential unreleased lock problem

PATCH In review Chengfeng Ye 2 participants 2 messages Aug 27, 2021 – Sep 8, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/axgbe: fix potential unreleased lock problem

The lock pdata->phy_mutex may not be correctly released if the function return in these two branches, which may lead to deadlock if the lock is acquired again.

Cc: [email protected]
Bugzilla ID: 776

---
 drivers/net/axgbe/axgbe_phy_impl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/axgbe/axgbe_phy_impl.c +4 -1
index 02236ec192..cf39095ee4 100644
@@ -418,8 +418,10 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)
 	 */
 	pthread_mutex_lock(&pdata->phy_mutex);
 
-	if (phy_data->comm_owned)
+	if (phy_data->comm_owned) {
+		pthread_mutex_unlock(&pdata->phy_mutex);
 		return 0;
+	}
 
 	/* Clear the mutexes */
 	XP_IOWRITE(pdata, XP_I2C_MUTEX, AXGBE_MUTEX_RELEASE);
@@ -444,6 +446,7 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)
 		XP_IOWRITE(pdata, XP_MDIO_MUTEX, mutex_id);
 
 		phy_data->comm_owned = 1;
+		pthread_mutex_unlock(&pdata->phy_mutex);
 		return 0;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 30 lines · Chengfeng Ye

The lock pdata->phy_mutex may not be correctly released if the function return in these two branches, which may lead to deadlock if the lock is acquired again.

Cc: [email protected]
Bugzilla ID: 776

---
 drivers/net/axgbe/axgbe_phy_impl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/axgbe/axgbe_phy_impl.c +3 -1
index 02236ec192..cf39095ee4 100644
@@ -418,8 +418,10 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)
 	 */
 	pthread_mutex_lock(&pdata->phy_mutex);
 
-	if (phy_data->comm_owned)
+	if (phy_data->comm_owned) {
+		pthread_mutex_unlock(&pdata->phy_mutex);
 		return 0;
+	}
 
 	/* Clear the mutexes */
 	XP_IOWRITE(pdata, XP_I2C_MUTEX, AXGBE_MUTEX_RELEASE);

drivers/net/axgbe/axgbe_phy_impl.c static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata) · line 452

Quoted 7 lines
drivers/net/axgbe/axgbe_phy_impl.c +1 -0
@@ -444,6 +446,7 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)
 		XP_IOWRITE(pdata, XP_MDIO_MUTEX, mutex_id);
 
 		phy_data->comm_owned = 1;
+		pthread_mutex_unlock(&pdata->phy_mutex);
 		return 0;
 	}
 

'axgbe_phy_get_comm_ownership()' seems intended to keep the lock on success. Please also check:

Fixes c8c2296b5974 ("net/axgbe: fix double unlock")

Perhaps you can comment the 'axgbe_phy_get_comm_ownership()' function instead?