lkml.org 
[lkml]   [2017]   [Nov]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 54/62] scsi: Remove idr_preload in st driver
Date
From: Matthew Wilcox <mawilcox@microsoft.com>

The IDR now has its own locking, so remove the driver's private lock
and calls to idr_preload.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
drivers/scsi/st.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index b141d7641a2e..e8703905c94a 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -221,7 +221,6 @@ static void scsi_tape_release(struct kref *);
#define to_scsi_tape(obj) container_of(obj, struct scsi_tape, kref)

static DEFINE_MUTEX(st_ref_mutex);
-static DEFINE_SPINLOCK(st_index_lock);
static DEFINE_SPINLOCK(st_use_lock);
static DEFINE_IDR(st_index_idr);

@@ -242,10 +241,11 @@ static struct scsi_tape *scsi_tape_get(int dev)
struct scsi_tape *STp = NULL;

mutex_lock(&st_ref_mutex);
- spin_lock(&st_index_lock);
+ idr_lock(&st_index_idr);

STp = idr_find(&st_index_idr, dev);
- if (!STp) goto out;
+ if (!STp)
+ goto out;

kref_get(&STp->kref);

@@ -261,7 +261,7 @@ static struct scsi_tape *scsi_tape_get(int dev)
kref_put(&STp->kref, scsi_tape_release);
STp = NULL;
out:
- spin_unlock(&st_index_lock);
+ idr_unlock(&st_index_idr);
mutex_unlock(&st_ref_mutex);
return STp;
}
@@ -4370,11 +4370,7 @@ static int st_probe(struct device *dev)
tpnt->blksize_changed = 0;
mutex_init(&tpnt->lock);

- idr_preload(GFP_KERNEL);
- spin_lock(&st_index_lock);
- error = idr_alloc(&st_index_idr, tpnt, 0, ST_MAX_TAPES + 1, GFP_NOWAIT);
- spin_unlock(&st_index_lock);
- idr_preload_end();
+ error = idr_alloc(&st_index_idr, tpnt, 0, ST_MAX_TAPES + 1, GFP_KERNEL);
if (error < 0) {
pr_warn("st: idr allocation failed: %d\n", error);
goto out_put_queue;
@@ -4408,9 +4404,7 @@ static int st_probe(struct device *dev)
remove_cdevs(tpnt);
kfree(tpnt->stats);
out_idr_remove:
- spin_lock(&st_index_lock);
idr_remove(&st_index_idr, tpnt->index);
- spin_unlock(&st_index_lock);
out_put_queue:
blk_put_queue(disk->queue);
out_put_disk:
@@ -4435,9 +4429,7 @@ static int st_remove(struct device *dev)
mutex_lock(&st_ref_mutex);
kref_put(&tpnt->kref, scsi_tape_release);
mutex_unlock(&st_ref_mutex);
- spin_lock(&st_index_lock);
idr_remove(&st_index_idr, index);
- spin_unlock(&st_index_lock);
return 0;
}

--
2.15.0
\
 
 \ /
  Last update: 2017-11-22 22:11    [W:0.190 / U:0.740 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site