aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r--drivers/scsi/sd.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4c5127ed379c..fbd8e1bbad38 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -49,6 +49,7 @@
49#include <linux/blkpg.h> 49#include <linux/blkpg.h>
50#include <linux/kref.h> 50#include <linux/kref.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/mutex.h>
52#include <asm/uaccess.h> 53#include <asm/uaccess.h>
53 54
54#include <scsi/scsi.h> 55#include <scsi/scsi.h>
@@ -111,7 +112,7 @@ static DEFINE_SPINLOCK(sd_index_lock);
111/* This semaphore is used to mediate the 0->1 reference get in the 112/* This semaphore is used to mediate the 0->1 reference get in the
112 * face of object destruction (i.e. we can't allow a get on an 113 * face of object destruction (i.e. we can't allow a get on an
113 * object after last put) */ 114 * object after last put) */
114static DECLARE_MUTEX(sd_ref_sem); 115static DEFINE_MUTEX(sd_ref_mutex);
115 116
116static int sd_revalidate_disk(struct gendisk *disk); 117static int sd_revalidate_disk(struct gendisk *disk);
117static void sd_rw_intr(struct scsi_cmnd * SCpnt); 118static void sd_rw_intr(struct scsi_cmnd * SCpnt);
@@ -193,9 +194,9 @@ static struct scsi_disk *scsi_disk_get(struct gendisk *disk)
193{ 194{
194 struct scsi_disk *sdkp; 195 struct scsi_disk *sdkp;
195 196
196 down(&sd_ref_sem); 197 mutex_lock(&sd_ref_mutex);
197 sdkp = __scsi_disk_get(disk); 198 sdkp = __scsi_disk_get(disk);
198 up(&sd_ref_sem); 199 mutex_unlock(&sd_ref_mutex);
199 return sdkp; 200 return sdkp;
200} 201}
201 202
@@ -203,11 +204,11 @@ static struct scsi_disk *scsi_disk_get_from_dev(struct device *dev)
203{ 204{
204 struct scsi_disk *sdkp; 205 struct scsi_disk *sdkp;
205 206
206 down(&sd_ref_sem); 207 mutex_lock(&sd_ref_mutex);
207 sdkp = dev_get_drvdata(dev); 208 sdkp = dev_get_drvdata(dev);
208 if (sdkp) 209 if (sdkp)
209 sdkp = __scsi_disk_get(sdkp->disk); 210 sdkp = __scsi_disk_get(sdkp->disk);
210 up(&sd_ref_sem); 211 mutex_unlock(&sd_ref_mutex);
211 return sdkp; 212 return sdkp;
212} 213}
213 214
@@ -215,10 +216,10 @@ static void scsi_disk_put(struct scsi_disk *sdkp)
215{ 216{
216 struct scsi_device *sdev = sdkp->device; 217 struct scsi_device *sdev = sdkp->device;
217 218
218 down(&sd_ref_sem); 219 mutex_lock(&sd_ref_mutex);
219 kref_put(&sdkp->kref, scsi_disk_release); 220 kref_put(&sdkp->kref, scsi_disk_release);
220 scsi_device_put(sdev); 221 scsi_device_put(sdev);
221 up(&sd_ref_sem); 222 mutex_unlock(&sd_ref_mutex);
222} 223}
223 224
224/** 225/**
@@ -1635,10 +1636,10 @@ static int sd_remove(struct device *dev)
1635 del_gendisk(sdkp->disk); 1636 del_gendisk(sdkp->disk);
1636 sd_shutdown(dev); 1637 sd_shutdown(dev);
1637 1638
1638 down(&sd_ref_sem); 1639 mutex_lock(&sd_ref_mutex);
1639 dev_set_drvdata(dev, NULL); 1640 dev_set_drvdata(dev, NULL);
1640 kref_put(&sdkp->kref, scsi_disk_release); 1641 kref_put(&sdkp->kref, scsi_disk_release);
1641 up(&sd_ref_sem); 1642 mutex_unlock(&sd_ref_mutex);
1642 1643
1643 return 0; 1644 return 0;
1644} 1645}
@@ -1647,7 +1648,7 @@ static int sd_remove(struct device *dev)
1647 * scsi_disk_release - Called to free the scsi_disk structure 1648 * scsi_disk_release - Called to free the scsi_disk structure
1648 * @kref: pointer to embedded kref 1649 * @kref: pointer to embedded kref
1649 * 1650 *
1650 * sd_ref_sem must be held entering this routine. Because it is 1651 * sd_ref_mutex must be held entering this routine. Because it is
1651 * called on last put, you should always use the scsi_disk_get() 1652 * called on last put, you should always use the scsi_disk_get()
1652 * scsi_disk_put() helpers which manipulate the semaphore directly 1653 * scsi_disk_put() helpers which manipulate the semaphore directly
1653 * and never do a direct kref_put(). 1654 * and never do a direct kref_put().