@@ -33,6 +33,7 @@
* check resource allocation in sr_init and some cleanups
*/
+#include <linux/find_atomic.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/kernel.h>
@@ -103,8 +104,7 @@ static struct scsi_driver sr_template = {
.done = sr_done,
};
-static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
-static DEFINE_SPINLOCK(sr_index_lock);
+static DECLARE_BITMAP(sr_index_bits, SR_DISKS);
static struct lock_class_key sr_bio_compl_lkclass;
@@ -566,10 +566,7 @@ static void sr_free_disk(struct gendisk *disk)
{
struct scsi_cd *cd = disk->private_data;
- spin_lock(&sr_index_lock);
clear_bit(MINOR(disk_devt(disk)), sr_index_bits);
- spin_unlock(&sr_index_lock);
-
unregister_cdrom(&cd->cdi);
mutex_destroy(&cd->lock);
kfree(cd);
@@ -628,15 +625,11 @@ static int sr_probe(struct device *dev)
goto fail_free;
mutex_init(&cd->lock);
- spin_lock(&sr_index_lock);
- minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
+ minor = find_and_set_bit(sr_index_bits, SR_DISKS);
if (minor == SR_DISKS) {
- spin_unlock(&sr_index_lock);
error = -EBUSY;
goto fail_put;
}
- __set_bit(minor, sr_index_bits);
- spin_unlock(&sr_index_lock);
disk->major = SCSI_CDROM_MAJOR;
disk->first_minor = minor;
@@ -700,9 +693,7 @@ static int sr_probe(struct device *dev)
unregister_cdrom:
unregister_cdrom(&cd->cdi);
fail_minor:
- spin_lock(&sr_index_lock);
clear_bit(minor, sr_index_bits);
- spin_unlock(&sr_index_lock);
fail_put:
put_disk(disk);
mutex_destroy(&cd->lock);
The driver accesses the sr_index_bits bitmaps to set/clear individual bits only. Now that we have an atomic bit search helper, we can drop the sr_index_lock that protects the sr_index_bits, and make all this routine lockless. While there, use DECLARE_BITMAP() to declare sr_index_bits. Signed-off-by: Yury Norov <yury.norov@gmail.com> --- drivers/scsi/sr.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)