diff mbox

scsi/fnic: Fix a sleep-in-atomic bug in fnic_handle_event

Message ID 1506999195-27236-1-git-send-email-baijiaju1990@163.com (mailing list archive)
State Deferred
Headers show

Commit Message

Jia-Ju Bai Oct. 3, 2017, 2:53 a.m. UTC
The driver may sleep under a spinlock, and the function call path is:
fnic_handle_event (acquire the spinlock)
  fnic_fcoe_start_fcf_disc
    fcoe_ctlr_link_up
      mutec_lock --> may sleep

To fix it, the spinlock can be released before fnic_fcoe_start_fcf_disc, 
and acquired again after this function.

This bug is found by my static analysis tool and my code review.

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
 drivers/scsi/fnic/fnic_fcs.c |    2 ++
 1 file changed, 2 insertions(+)
diff mbox

Patch

diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c
index 999fc75..4c99c96 100644
--- a/drivers/scsi/fnic/fnic_fcs.c
+++ b/drivers/scsi/fnic/fnic_fcs.c
@@ -265,7 +265,9 @@  void fnic_handle_event(struct work_struct *work)
 		case FNIC_EVT_START_FCF_DISC:
 			FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
 				  "Start FCF Discovery\n");
+			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
 			fnic_fcoe_start_fcf_disc(fnic);
+			spin_lock_irqsave(&fnic->fnic_lock, flags);
 			break;
 		default:
 			FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,