Skip to contentSkip to conversation

bnx2fc: Fix locking requirements in bnx2fc_init_tgt

PATCH In review Bastien Philbert 3 participants 4 messages Apr 5, 2016 – Apr 6, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bnx2fc: Fix locking requirements in bnx2fc_init_tgt

This fixes the locking around the call to bnx2fc_alloc_id to comply with the comments about this particular function's definition about requiring the need to hold the hba mutex before and after calling it.

---
 drivers/scsi/bnx2fc/bnx2fc_tgt.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/bnx2fc/bnx2fc_tgt.c +5 -1
index 08ec318..f2988cd 100644
@@ -368,9 +368,13 @@ static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
 		return -1;
 	}
 
+	mutex_lock(&hba->hba_mutex);
 	tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
-	if (tgt->fcoe_conn_id == -1)
+	if (tgt->fcoe_conn_id == -1) {
+		mutex_unlock(&hba->hba_mutex);
 		return -1;
+	}
+	mutex_unlock(&hba->hba_mutex);
 
 	BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n", tgt->fcoe_conn_id);
 
Signature · 1 line
2.5.0
#1 lore raw
Quoted 19 lines · Bastien Philbert

This fixes the locking around the call to bnx2fc_alloc_id to comply with the comments about this particular function's definition about requiring the need to hold the hba mutex before and after calling it.

---
drivers/scsi/bnx2fc/bnx2fc_tgt.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/bnx2fc/bnx2fc_tgt.c +1 -0
index 08ec318..f2988cd 100644
@@ -368,9 +368,13 @@ static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
 		return -1;
 	}
 
+	mutex_lock(&hba->hba_mutex);

drivers/scsi/bnx2fc/bnx2fc_tgt.c static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt, · line 380

Quoted 10 lines
drivers/scsi/bnx2fc/bnx2fc_tgt.c +4 -1
 	tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
-	if (tgt->fcoe_conn_id == -1)
+	if (tgt->fcoe_conn_id == -1) {
+		mutex_unlock(&hba->hba_mutex);
 		return -1;
+	}
+	mutex_unlock(&hba->hba_mutex);
 
 	BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n", tgt->fcoe_conn_id);
 

Taking the mutex here is not needed as it is already taken in bnx2fc_rport_event_handler() in the call chain bnx2fc_rport_event_handler->bnx2fc_offload_session->bnx2fc_init_tgt->bnx2fc_alloc_conn_id

#2 lore raw
Quoted 31 lines · Chad Dupuis
Quoted 27 lines · Bastien Philbert

This fixes the locking around the call to bnx2fc_alloc_id to comply with the comments about this particular function's definition about requiring the need to hold the hba mutex before and after calling it.

---
drivers/scsi/bnx2fc/bnx2fc_tgt.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/bnx2fc/bnx2fc_tgt.c +5 -1
index 08ec318..f2988cd 100644
@@ -368,9 +368,13 @@ static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
                return -1;
        }
 
+       mutex_lock(&hba->hba_mutex);
        tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
-       if (tgt->fcoe_conn_id == -1)
+       if (tgt->fcoe_conn_id == -1) {
+               mutex_unlock(&hba->hba_mutex);
                return -1;
+       }
+       mutex_unlock(&hba->hba_mutex);
 
Quoted 8 lines

drivers/scsi/bnx2fc/bnx2fc_tgt.c static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt, · line 380

Quoted 4 lines
drivers/scsi/bnx2fc/bnx2fc_tgt.c +0 -0
        BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n",
 tgt->fcoe_conn_id);

Taking the mutex here is not needed as it is already taken in bnx2fc_rport_event_handler() in the call chain bnx2fc_rport_event_handler->bnx2fc_offload_session->bnx2fc_init_tgt->bnx2fc_alloc_conn_id

Ok thanks and good to known.
Bastien

#3 lore raw
Quoted 45 lines · Bastien Bastien Philbert
Quoted 34 lines · Chad Dupuis
Quoted 30 lines · Bastien Philbert

This fixes the locking around the call to bnx2fc_alloc_id to comply
with the comments about this particular function's definition about
requiring the need to hold the hba mutex before and after calling it.

---
drivers/scsi/bnx2fc/bnx2fc_tgt.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/bnx2fc/bnx2fc_tgt.c +5 -1
index 08ec318..f2988cd 100644
@@ -368,9 +368,13 @@ static int bnx2fc_init_tgt(struct
 bnx2fc_rport *tgt,
                return -1;
        }
 
+       mutex_lock(&hba->hba_mutex);
        tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
-       if (tgt->fcoe_conn_id == -1)
+       if (tgt->fcoe_conn_id == -1) {
+               mutex_unlock(&hba->hba_mutex);
                return -1;
+       }
+       mutex_unlock(&hba->hba_mutex);
 
Quoted 9 lines
Quoted 4 lines
drivers/scsi/bnx2fc/bnx2fc_tgt.c +0 -0
        BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n",

tgt->fcoe_conn_id);

Taking the mutex here is not needed as it is already taken in bnx2fc_rport_event_handler() in the call chain bnx2fc_rport_event_handler->bnx2fc_offload_session->bnx2fc_init_tgt ->bnx2fc_alloc_conn_id

Quoted 1 line

Ok thanks and good to known.

Since the mutex was already taken, the patch you propose would produce an immediate deadlock if applied, meaning you didn't actually test it out. If you're going to propose patches like this, please understand the driver you're patching, *test* the patches on actual hardware and describe the problem you're solving in the changelog.

Thanks,

James