[v2] net/axgbe: fix potential unreleased lock problem

Message ID 20210826190258.108062-1-cyeaa@connect.ust.hk (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] net/axgbe: fix potential unreleased lock problem |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing fail Testing issues
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-aarch64-unit-testing fail Testing issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

YE Chengfeng Aug. 26, 2021, 7:02 p.m. UTC
  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: cyeaa@connect.ust.hk
Bugzilla ID: 776

Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
---
 drivers/net/axgbe/axgbe_phy_impl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Ferruh Yigit Sept. 8, 2021, 1:39 p.m. UTC | #1
On 8/26/2021 8:02 PM, Chengfeng Ye wrote:
> 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: cyeaa@connect.ust.hk
> Bugzilla ID: 776
> 
> Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
> ---
>  drivers/net/axgbe/axgbe_phy_impl.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
> index 02236ec192..cf39095ee4 100644
> --- a/drivers/net/axgbe/axgbe_phy_impl.c
> +++ b/drivers/net/axgbe/axgbe_phy_impl.c
> @@ -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;
>  	}
>  
> 


'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?
  

Patch

diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
index 02236ec192..cf39095ee4 100644
--- a/drivers/net/axgbe/axgbe_phy_impl.c
+++ b/drivers/net/axgbe/axgbe_phy_impl.c
@@ -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;
 	}