From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 869B9A2EFC for ; Thu, 19 Sep 2019 13:02:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 805A61EF47; Thu, 19 Sep 2019 13:02:38 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 9842D1EF2E; Thu, 19 Sep 2019 13:02:36 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Sep 2019 04:02:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,523,1559545200"; d="scan'208";a="212182400" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga004.fm.intel.com with ESMTP; 19 Sep 2019 04:02:34 -0700 Received: from wgcvswdev001.ir.intel.com (wgcvswdev001.ir.intel.com [10.102.246.100]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x8JB2XQ0030947; Thu, 19 Sep 2019 12:02:33 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id x8JB1tKE010472; Thu, 19 Sep 2019 12:01:55 +0100 Received: (from ppoornix@localhost) by wgcvswdev001.ir.intel.com with œ id x8JB1sSY010468; Thu, 19 Sep 2019 12:01:54 +0100 From: Pallantla Poornima To: dev@dpdk.org Cc: reshma.pattan@intel.com, jananeex.m.parthasarathy@intel.com, ravi1.kumar@amd.com, Pallantla Poornima , stable@dpdk.org Date: Thu, 19 Sep 2019 12:01:47 +0100 Message-Id: <1568890907-10123-1-git-send-email-pallantlax.poornima@intel.com> X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH] net/axgbe: fix double unlock coverity issue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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