diff mbox series

[net-next,02/15] iavf: obtain the crit_section lock in iavf_open() immediately

Message ID 20210604165335.33329-2-anthony.l.nguyen@intel.com
State Deferred
Delegated to: Anthony Nguyen
Headers show
Series [net-next,01/15] iavf: correctly track whether the interface is running during resets | expand

Commit Message

Tony Nguyen June 4, 2021, 4:53 p.m. UTC
From: Nicholas Nunley <nicholas.d.nunley@intel.com>

iavf_open() checks for IAVF_FLAG_PF_COMMS_FAILED outside of the
crit_section lock so that it can return early if possible, without needing
to acquire the lock. This is perfectly fine, but once the lock is actually
obtained the code assumes the value hasn't changed. This is not correct,
since the IAVF_FLAG_PF_COMMS_FAILED field can certainly change by the time
the lock is obtained, especially if iavf_open() has to wait for it while
iavf_reset_task() runs on another thread.

To avoid this, simply grab the lock before checking the value.

Signed-off-by: Nicholas Nunley <nicholas.d.nunley@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index bf96a9dab962..4c55773c6ee1 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -3196,15 +3196,16 @@  static int iavf_open(struct net_device *netdev)
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 	int err;
 
-	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) {
-		dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
-		return -EIO;
-	}
-
 	while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
 				&adapter->crit_section))
 		usleep_range(500, 1000);
 
+	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) {
+		dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
+		err = -EIO;
+		goto err_unlock;
+	}
+
 	if (adapter->state != __IAVF_DOWN) {
 		err = -EBUSY;
 		goto err_unlock;