diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2010-06-15 07:21:11 -0400 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2010-08-07 12:15:36 -0400 |
commit | 575cfc673e0f2e6f71ccc01bb77d7ec811054048 (patch) | |
tree | 696bdbfec6870511493962c7786506e5c61e2948 /drivers/block | |
parent | 41a55b4de396f675485a3f3cb3e1b117316e9ce9 (diff) |
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')
-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); | |||
578 | #define NEED_1_RECAL -2 | 578 | #define NEED_1_RECAL -2 |
579 | #define NEED_2_RECAL -3 | 579 | #define NEED_2_RECAL -3 |
580 | 580 | ||
581 | static int usage_count; | 581 | static atomic_t usage_count = ATOMIC_INIT(0); |
582 | 582 | ||
583 | /* buffer related variables */ | 583 | /* buffer related variables */ |
584 | static int buffer_track = -1; | 584 | static int buffer_track = -1; |
@@ -860,7 +860,7 @@ static void set_fdc(int drive) | |||
860 | /* locks the driver */ | 860 | /* locks the driver */ |
861 | static int _lock_fdc(int drive, bool interruptible, int line) | 861 | static int _lock_fdc(int drive, bool interruptible, int line) |
862 | { | 862 | { |
863 | if (!usage_count) { | 863 | if (atomic_read(&usage_count) == 0) { |
864 | pr_err("Trying to lock fdc while usage count=0 at line %d\n", | 864 | pr_err("Trying to lock fdc while usage count=0 at line %d\n", |
865 | line); | 865 | line); |
866 | return -1; | 866 | return -1; |
@@ -2941,7 +2941,7 @@ static void do_fd_request(struct request_queue *q) | |||
2941 | return; | 2941 | return; |
2942 | } | 2942 | } |
2943 | 2943 | ||
2944 | if (usage_count == 0) { | 2944 | if (atomic_read(&usage_count) == 0) { |
2945 | pr_info("warning: usage count=0, current_req=%p exiting\n", | 2945 | pr_info("warning: usage count=0, current_req=%p exiting\n", |
2946 | current_req); | 2946 | current_req); |
2947 | pr_info("sect=%ld type=%x flags=%x\n", | 2947 | pr_info("sect=%ld type=%x flags=%x\n", |
@@ -3858,7 +3858,7 @@ static int floppy_revalidate(struct gendisk *disk) | |||
3858 | if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || | 3858 | if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
3859 | test_bit(FD_VERIFY_BIT, &UDRS->flags) || | 3859 | test_bit(FD_VERIFY_BIT, &UDRS->flags) || |
3860 | test_bit(drive, &fake_change) || NO_GEOM) { | 3860 | test_bit(drive, &fake_change) || NO_GEOM) { |
3861 | if (usage_count == 0) { | 3861 | if (atomic_read(&usage_count) == 0) { |
3862 | pr_info("VFS: revalidate called on non-open device.\n"); | 3862 | pr_info("VFS: revalidate called on non-open device.\n"); |
3863 | return -EFAULT; | 3863 | return -EFAULT; |
3864 | } | 3864 | } |
@@ -4357,7 +4357,7 @@ out_unreg_platform_dev: | |||
4357 | platform_device_unregister(&floppy_device[drive]); | 4357 | platform_device_unregister(&floppy_device[drive]); |
4358 | out_flush_work: | 4358 | out_flush_work: |
4359 | flush_scheduled_work(); | 4359 | flush_scheduled_work(); |
4360 | if (usage_count) | 4360 | if (atomic_read(&usage_count)) |
4361 | floppy_release_irq_and_dma(); | 4361 | floppy_release_irq_and_dma(); |
4362 | out_unreg_region: | 4362 | out_unreg_region: |
4363 | blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); | 4363 | blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); |
@@ -4374,8 +4374,6 @@ out_put_disk: | |||
4374 | return err; | 4374 | return err; |
4375 | } | 4375 | } |
4376 | 4376 | ||
4377 | static DEFINE_SPINLOCK(floppy_usage_lock); | ||
4378 | |||
4379 | static const struct io_region { | 4377 | static const struct io_region { |
4380 | int offset; | 4378 | int offset; |
4381 | int size; | 4379 | int size; |
@@ -4421,14 +4419,8 @@ static void floppy_release_regions(int fdc) | |||
4421 | 4419 | ||
4422 | static int floppy_grab_irq_and_dma(void) | 4420 | static int floppy_grab_irq_and_dma(void) |
4423 | { | 4421 | { |
4424 | unsigned long flags; | 4422 | if (atomic_inc_return(&usage_count) > 1) |
4425 | |||
4426 | spin_lock_irqsave(&floppy_usage_lock, flags); | ||
4427 | if (usage_count++) { | ||
4428 | spin_unlock_irqrestore(&floppy_usage_lock, flags); | ||
4429 | return 0; | 4423 | return 0; |
4430 | } | ||
4431 | spin_unlock_irqrestore(&floppy_usage_lock, flags); | ||
4432 | 4424 | ||
4433 | /* | 4425 | /* |
4434 | * We might have scheduled a free_irq(), wait it to | 4426 | * We might have scheduled a free_irq(), wait it to |
@@ -4439,9 +4431,7 @@ static int floppy_grab_irq_and_dma(void) | |||
4439 | if (fd_request_irq()) { | 4431 | if (fd_request_irq()) { |
4440 | DPRINT("Unable to grab IRQ%d for the floppy driver\n", | 4432 | DPRINT("Unable to grab IRQ%d for the floppy driver\n", |
4441 | FLOPPY_IRQ); | 4433 | FLOPPY_IRQ); |
4442 | spin_lock_irqsave(&floppy_usage_lock, flags); | 4434 | atomic_dec(&usage_count); |
4443 | usage_count--; | ||
4444 | spin_unlock_irqrestore(&floppy_usage_lock, flags); | ||
4445 | return -1; | 4435 | return -1; |
4446 | } | 4436 | } |
4447 | if (fd_request_dma()) { | 4437 | if (fd_request_dma()) { |
@@ -4451,9 +4441,7 @@ static int floppy_grab_irq_and_dma(void) | |||
4451 | use_virtual_dma = can_use_virtual_dma = 1; | 4441 | use_virtual_dma = can_use_virtual_dma = 1; |
4452 | if (!(can_use_virtual_dma & 1)) { | 4442 | if (!(can_use_virtual_dma & 1)) { |
4453 | fd_free_irq(); | 4443 | fd_free_irq(); |
4454 | spin_lock_irqsave(&floppy_usage_lock, flags); | 4444 | atomic_dec(&usage_count); |
4455 | usage_count--; | ||
4456 | spin_unlock_irqrestore(&floppy_usage_lock, flags); | ||
4457 | return -1; | 4445 | return -1; |
4458 | } | 4446 | } |
4459 | } | 4447 | } |
@@ -4488,9 +4476,7 @@ cleanup: | |||
4488 | fd_free_dma(); | 4476 | fd_free_dma(); |
4489 | while (--fdc >= 0) | 4477 | while (--fdc >= 0) |
4490 | floppy_release_regions(fdc); | 4478 | floppy_release_regions(fdc); |
4491 | spin_lock_irqsave(&floppy_usage_lock, flags); | 4479 | atomic_dec(&usage_count); |
4492 | usage_count--; | ||
4493 | spin_unlock_irqrestore(&floppy_usage_lock, flags); | ||
4494 | return -1; | 4480 | return -1; |
4495 | } | 4481 | } |
4496 | 4482 | ||
@@ -4502,14 +4488,10 @@ static void floppy_release_irq_and_dma(void) | |||
4502 | #endif | 4488 | #endif |
4503 | long tmpsize; | 4489 | long tmpsize; |
4504 | unsigned long tmpaddr; | 4490 | unsigned long tmpaddr; |
4505 | unsigned long flags; | ||
4506 | 4491 | ||
4507 | spin_lock_irqsave(&floppy_usage_lock, flags); | 4492 | if (!atomic_dec_and_test(&usage_count)) |
4508 | if (--usage_count) { | ||
4509 | spin_unlock_irqrestore(&floppy_usage_lock, flags); | ||
4510 | return; | 4493 | return; |
4511 | } | 4494 | |
4512 | spin_unlock_irqrestore(&floppy_usage_lock, flags); | ||
4513 | if (irqdma_allocated) { | 4495 | if (irqdma_allocated) { |
4514 | fd_disable_dma(); | 4496 | fd_disable_dma(); |
4515 | fd_free_dma(); | 4497 | fd_free_dma(); |
@@ -4602,7 +4584,7 @@ static void __exit floppy_module_exit(void) | |||
4602 | del_timer_sync(&fd_timer); | 4584 | del_timer_sync(&fd_timer); |
4603 | blk_cleanup_queue(floppy_queue); | 4585 | blk_cleanup_queue(floppy_queue); |
4604 | 4586 | ||
4605 | if (usage_count) | 4587 | if (atomic_read(&usage_count)) |
4606 | floppy_release_irq_and_dma(); | 4588 | floppy_release_irq_and_dma(); |
4607 | 4589 | ||
4608 | /* eject disk, if any */ | 4590 | /* eject disk, if any */ |