From a305a5284cac23adbf7f86b3014cc2e6325c7b88 Mon Sep 17 00:00:00 2001
From: Akinobu Mita <akinobu.mita@gmail.com>
Date: Wed, 29 Apr 2015 10:02:17 +0900
Subject: [PATCH] scsi: ufs: fix ufshcd_set_dev_pwr_mode() when unloading
module
---
drivers/scsi/ufs/ufshcd.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
@@ -4695,23 +4695,19 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
struct scsi_sense_hdr sshdr;
struct scsi_device *sdp;
unsigned long flags;
- int ret;
+ int ret = 0;
+ mutex_lock(&hba->host->scan_mutex);
spin_lock_irqsave(hba->host->host_lock, flags);
sdp = hba->sdev_ufs_device;
- if (sdp) {
- ret = scsi_device_get(sdp);
- if (!ret && !scsi_device_online(sdp)) {
- ret = -ENODEV;
- scsi_device_put(sdp);
- }
- } else {
+ if (!sdp || !scsi_device_online(sdp))
ret = -ENODEV;
- }
spin_unlock_irqrestore(hba->host->host_lock, flags);
- if (ret)
+ if (ret) {
+ mutex_unlock(&hba->host->scan_mutex);
return ret;
+ }
/*
* If scsi commands fail, the scsi mid-layer schedules scsi error-
@@ -4748,7 +4744,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
if (!ret)
hba->curr_dev_pwr_mode = pwr_mode;
out:
- scsi_device_put(sdp);
+ mutex_unlock(&hba->host->scan_mutex);
hba->host->eh_noresume = 0;
return ret;
}
--
1.9.1