DPDK patches and discussions
 help / color / Atom feed
* [dpdk-dev] [PATCH] net/axgbe: fix double unlock coverity issue
@ 2019-09-19 11:01 Pallantla Poornima
  2019-09-25  6:03 ` Poornima, PallantlaX
  2019-10-09  8:41 ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
  0 siblings, 2 replies; 6+ messages in thread
From: Pallantla Poornima @ 2019-09-19 11:01 UTC (permalink / raw)
  To: dev
  Cc: reshma.pattan, jananeex.m.parthasarathy, ravi1.kumar,
	Pallantla Poornima, stable

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: a5c7273771 ("net/axgbe: add phy programming APIs")
Cc: stable@dpdk.org

Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
---
 drivers/net/axgbe/axgbe_phy_impl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
index 973177f69..2267c5f81 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);
-- 
2.17.2


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

* Re: [dpdk-dev] [PATCH] net/axgbe: fix double unlock coverity issue
  2019-09-19 11:01 [dpdk-dev] [PATCH] net/axgbe: fix double unlock coverity issue Pallantla Poornima
@ 2019-09-25  6:03 ` Poornima, PallantlaX
  2019-10-09  8:41 ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
  1 sibling, 0 replies; 6+ messages in thread
From: Poornima, PallantlaX @ 2019-09-25  6:03 UTC (permalink / raw)
  To: dev; +Cc: Pattan, Reshma, Parthasarathy, JananeeX M, ravi1.kumar, stable

Hi,

>-----Original Message-----
>From: Poornima, PallantlaX
>Sent: Thursday, September 19, 2019 4:32 PM
>To: dev@dpdk.org
>Cc: Pattan, Reshma <reshma.pattan@intel.com>; Parthasarathy, JananeeX M
><jananeex.m.parthasarathy@intel.com>; ravi1.kumar@amd.com; Poornima,
>PallantlaX <pallantlax.poornima@intel.com>; stable@dpdk.org
>Subject: [PATCH] net/axgbe: fix double unlock coverity issue
>
>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: a5c7273771 ("net/axgbe: add phy programming APIs")
>Cc: stable@dpdk.org
>
>Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
>---
> drivers/net/axgbe/axgbe_phy_impl.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>

Request for review.


Thanks,
Poornima

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

* Re: [dpdk-dev] [dpdk-stable] [PATCH] net/axgbe: fix double unlock coverity issue
  2019-09-19 11:01 [dpdk-dev] [PATCH] net/axgbe: fix double unlock coverity issue Pallantla Poornima
  2019-09-25  6:03 ` Poornima, PallantlaX
@ 2019-10-09  8:41 ` " Ferruh Yigit
  2019-10-18 16:53   ` Ferruh Yigit
  1 sibling, 1 reply; 6+ messages in thread
From: Ferruh Yigit @ 2019-10-09  8:41 UTC (permalink / raw)
  To: Pallantla Poornima, dev, ravi1.kumar
  Cc: reshma.pattan, jananeex.m.parthasarathy, stable

On 9/19/2019 12:01 PM, Pallantla Poornima wrote:
> 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: a5c7273771 ("net/axgbe: add phy programming APIs")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>

lgtm, 'axgbe_phy_put_comm_ownership()' expects 'axgbe_phy_get_comm_ownership()'
gets the lock. Thanks for fixing the coverity issue.

But still, Ravi can you please review/test the patch?

Thanks,
ferruh

> ---
>  drivers/net/axgbe/axgbe_phy_impl.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
> index 973177f69..2267c5f81 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);
> 


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

* Re: [dpdk-dev] [dpdk-stable] [PATCH] net/axgbe: fix double unlock coverity issue
  2019-10-09  8:41 ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
@ 2019-10-18 16:53   ` Ferruh Yigit
  2019-10-21  8:20     ` Kumar, Ravi1
  0 siblings, 1 reply; 6+ messages in thread
From: Ferruh Yigit @ 2019-10-18 16:53 UTC (permalink / raw)
  To: Pallantla Poornima, dev, ravi1.kumar
  Cc: reshma.pattan, jananeex.m.parthasarathy, stable

On 10/9/2019 9:41 AM, Ferruh Yigit wrote:
> On 9/19/2019 12:01 PM, Pallantla Poornima wrote:
>> 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: a5c7273771 ("net/axgbe: add phy programming APIs")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
> 
> lgtm, 'axgbe_phy_put_comm_ownership()' expects 'axgbe_phy_get_comm_ownership()'
> gets the lock. Thanks for fixing the coverity issue.
> 
> But still, Ravi can you please review/test the patch?
> 

If there is no objection the patch will be merged soon.

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

* Re: [dpdk-dev] [dpdk-stable] [PATCH] net/axgbe: fix double unlock coverity issue
  2019-10-18 16:53   ` Ferruh Yigit
@ 2019-10-21  8:20     ` Kumar, Ravi1
  2019-10-21  9:09       ` Ferruh Yigit
  0 siblings, 1 reply; 6+ messages in thread
From: Kumar, Ravi1 @ 2019-10-21  8:20 UTC (permalink / raw)
  To: Ferruh Yigit, Pallantla Poornima, dev
  Cc: reshma.pattan, jananeex.m.parthasarathy, stable

>On 10/9/2019 9:41 AM, Ferruh Yigit wrote:
>> On 9/19/2019 12:01 PM, Pallantla Poornima wrote:
>>> 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: a5c7273771 ("net/axgbe: add phy programming APIs")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
>>
>> lgtm, 'axgbe_phy_put_comm_ownership()' expects 'axgbe_phy_get_comm_ownership()'
>> gets the lock. Thanks for fixing the coverity issue.
>>
>> But still, Ravi can you please review/test the patch?
>>
>
>If there is no objection the patch will be merged soon.
>
Looks good to me. Ok to merge.

Regards,
Ravi

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

* Re: [dpdk-dev] [dpdk-stable] [PATCH] net/axgbe: fix double unlock coverity issue
  2019-10-21  8:20     ` Kumar, Ravi1
@ 2019-10-21  9:09       ` Ferruh Yigit
  0 siblings, 0 replies; 6+ messages in thread
From: Ferruh Yigit @ 2019-10-21  9:09 UTC (permalink / raw)
  To: Kumar, Ravi1, Pallantla Poornima, dev
  Cc: reshma.pattan, jananeex.m.parthasarathy, stable

On 10/21/2019 9:20 AM, Kumar, Ravi1 wrote:
>> On 10/9/2019 9:41 AM, Ferruh Yigit wrote:
>>> On 9/19/2019 12:01 PM, Pallantla Poornima wrote:
>>>> 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: a5c7273771 ("net/axgbe: add phy programming APIs")
>>>> Cc: stable@dpdk.org
>>>>
>>>> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
>>>
>>> lgtm, 'axgbe_phy_put_comm_ownership()' expects 'axgbe_phy_get_comm_ownership()'
>>> gets the lock. Thanks for fixing the coverity issue.
>>>
>>> But still, Ravi can you please review/test the patch?
>>>
>>
>> If there is no objection the patch will be merged soon.
>>
> Looks good to me. Ok to merge.

(Converting to explicit Ack)
Acked-by: Ravi Kumar <ravi1.kumar@amd.com>

Applied to dpdk-next-net/master, thanks.

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-19 11:01 [dpdk-dev] [PATCH] net/axgbe: fix double unlock coverity issue Pallantla Poornima
2019-09-25  6:03 ` Poornima, PallantlaX
2019-10-09  8:41 ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
2019-10-18 16:53   ` Ferruh Yigit
2019-10-21  8:20     ` Kumar, Ravi1
2019-10-21  9:09       ` Ferruh Yigit

DPDK patches and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox