diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2010-06-15 13:21:11 +0200 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2010-08-07 18:15:36 +0200 |
commit | 575cfc673e0f2e6f71ccc01bb77d7ec811054048 (patch) | |
tree | 696bdbfec6870511493962c7786506e5c61e2948 /drivers/block/floppy.c | |
parent | 41a55b4de396f675485a3f3cb3e1b117316e9ce9 (diff) | |
download | kernel-common-575cfc673e0f2e6f71ccc01bb77d7ec811054048.tar.gz kernel-common-575cfc673e0f2e6f71ccc01bb77d7ec811054048.tar.bz2 kernel-common-575cfc673e0f2e6f71ccc01bb77d7ec811054048.zip |
floppy: use atomic type for usage_count
The usage_count was being protected by a lock which was only there to
create an atomic counter.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'drivers/block/floppy.c')
-rw-r--r-- | drivers/block/floppy.c | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 5816387f9bce..9b4746871227 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -578,7 +578,7 @@ static void reset_fdc(void); #define NEED_1_RECAL -2 #define NEED_2_RECAL -3 -static int usage_count; +static atomic_t usage_count = ATOMIC_INIT(0); /* buffer related variables */ static int buffer_track = -1; @@ -860,7 +860,7 @@ static void set_fdc(int drive) /* locks the driver */ static int _lock_fdc(int drive, bool interruptible, int line) { - if (!usage_count) { + if (atomic_read(&usage_count) == 0) { pr_err("Trying to lock fdc while usage count=0 at line %d\n", line); return -1; @@ -2941,7 +2941,7 @@ static void do_fd_request(struct request_queue *q) return; } - if (usage_count == 0) { + if (atomic_read(&usage_count) == 0) { pr_info("warning: usage count=0, current_req=%p exiting\n", current_req); pr_info("sect=%ld type=%x flags=%x\n", @@ -3858,7 +3858,7 @@ static int floppy_revalidate(struct gendisk *disk) if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || test_bit(FD_VERIFY_BIT, &UDRS->flags) || test_bit(drive, &fake_change) || NO_GEOM) { - if (usage_count == 0) { + if (atomic_read(&usage_count) == 0) { pr_info("VFS: revalidate called on non-open device.\n"); return -EFAULT; } @@ -4357,7 +4357,7 @@ out_unreg_platform_dev: platform_device_unregister(&floppy_device[drive]); out_flush_work: flush_scheduled_work(); - if (usage_count) + if (atomic_read(&usage_count)) floppy_release_irq_and_dma(); out_unreg_region: blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); @@ -4374,8 +4374,6 @@ out_put_disk: return err; } -static DEFINE_SPINLOCK(floppy_usage_lock); - static const struct io_region { int offset; int size; @@ -4421,14 +4419,8 @@ static void floppy_release_regions(int fdc) static int floppy_grab_irq_and_dma(void) { - unsigned long flags; - - spin_lock_irqsave(&floppy_usage_lock, flags); - if (usage_count++) { - spin_unlock_irqrestore(&floppy_usage_lock, flags); + if (atomic_inc_return(&usage_count) > 1) return 0; - } - spin_unlock_irqrestore(&floppy_usage_lock, flags); /* * We might have scheduled a free_irq(), wait it to @@ -4439,9 +4431,7 @@ static int floppy_grab_irq_and_dma(void) if (fd_request_irq()) { DPRINT("Unable to grab IRQ%d for the floppy driver\n", FLOPPY_IRQ); - spin_lock_irqsave(&floppy_usage_lock, flags); - usage_count--; - spin_unlock_irqrestore(&floppy_usage_lock, flags); + atomic_dec(&usage_count); return -1; } if (fd_request_dma()) { @@ -4451,9 +4441,7 @@ static int floppy_grab_irq_and_dma(void) use_virtual_dma = can_use_virtual_dma = 1; if (!(can_use_virtual_dma & 1)) { fd_free_irq(); - spin_lock_irqsave(&floppy_usage_lock, flags); - usage_count--; - spin_unlock_irqrestore(&floppy_usage_lock, flags); + atomic_dec(&usage_count); return -1; } } @@ -4488,9 +4476,7 @@ cleanup: fd_free_dma(); while (--fdc >= 0) floppy_release_regions(fdc); - spin_lock_irqsave(&floppy_usage_lock, flags); - usage_count--; - spin_unlock_irqrestore(&floppy_usage_lock, flags); + atomic_dec(&usage_count); return -1; } @@ -4502,14 +4488,10 @@ static void floppy_release_irq_and_dma(void) #endif long tmpsize; unsigned long tmpaddr; - unsigned long flags; - spin_lock_irqsave(&floppy_usage_lock, flags); - if (--usage_count) { - spin_unlock_irqrestore(&floppy_usage_lock, flags); + if (!atomic_dec_and_test(&usage_count)) return; - } - spin_unlock_irqrestore(&floppy_usage_lock, flags); + if (irqdma_allocated) { fd_disable_dma(); fd_free_dma(); @@ -4602,7 +4584,7 @@ static void __exit floppy_module_exit(void) del_timer_sync(&fd_timer); blk_cleanup_queue(floppy_queue); - if (usage_count) + if (atomic_read(&usage_count)) floppy_release_irq_and_dma(); /* eject disk, if any */ |