summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/sd-as3525v2.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/sd-as3525v2.c')
-rw-r--r--firmware/target/arm/as3525/sd-as3525v2.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c
index ae3dde4495..b4ac40152b 100644
--- a/firmware/target/arm/as3525/sd-as3525v2.c
+++ b/firmware/target/arm/as3525/sd-as3525v2.c
@@ -598,21 +598,13 @@ static void sd_thread(void)
598 { 598 {
599#ifdef HAVE_HOTSWAP 599#ifdef HAVE_HOTSWAP
600 case SYS_HOTSWAP_INSERTED: 600 case SYS_HOTSWAP_INSERTED:
601 case SYS_HOTSWAP_EXTRACTED: 601 case SYS_HOTSWAP_EXTRACTED:;
602 { 602 int success = 1;
603 int changed = 1; 603
604 fat_lock(); /* lock-out FAT activity first - 604 disk_unmount(SD_SLOT_AS3525); /* release "by force" */
605 prevent deadlocking via disk_mount that 605
606 would cause a reverse-order attempt with 606 mutex_lock(&sd_mtx); /* lock-out card activity */
607 another thread */ 607
608 mutex_lock(&sd_mtx); /* lock-out card activity - direct calls
609 into driver that bypass the fat cache */
610
611 /* We now have exclusive control of fat cache and ata */
612
613 disk_unmount(SD_SLOT_AS3525); /* release "by force", ensure file
614 descriptors aren't leaked and any busy
615 ones are invalid if mounting */
616 /* Force card init for new card, re-init for re-inserted one or 608 /* Force card init for new card, re-init for re-inserted one or
617 * clear if the last attempt to init failed with an error. */ 609 * clear if the last attempt to init failed with an error. */
618 card_info[SD_SLOT_AS3525].initialized = 0; 610 card_info[SD_SLOT_AS3525].initialized = 0;
@@ -620,24 +612,25 @@ static void sd_thread(void)
620 if (ev.id == SYS_HOTSWAP_INSERTED) 612 if (ev.id == SYS_HOTSWAP_INSERTED)
621 { 613 {
622 sd_enable(true); 614 sd_enable(true);
623 changed = (sd_init_card(SD_SLOT_AS3525) == 0) && disk_mount(SD_SLOT_AS3525); /* 0 if fail */ 615 success = sd_init_card(SD_SLOT_AS3525) == 0 ? 2 : 0;
616 sd_enable(false);
624 } 617 }
625 618
619 mutex_unlock(&sd_mtx);
620
621 if (success > 1)
622 success = disk_mount(SD_SLOT_AS3525); /* 0 if fail */
623
626 /* 624 /*
627 * Mount succeeded, or this was an EXTRACTED event, 625 * Mount succeeded, or this was an EXTRACTED event,
628 * in both cases notify the system about the changed filesystems 626 * in both cases notify the system about the changed filesystems
629 */ 627 */
630 if (changed) 628 if (success)
631 queue_broadcast(SYS_FS_CHANGED, 0); 629 queue_broadcast(SYS_FS_CHANGED, 0);
632 630
633 sd_enable(false);
634
635 /* Access is now safe */
636 mutex_unlock(&sd_mtx);
637 fat_unlock();
638 }
639 break; 631 break;
640#endif 632#endif /* HAVE_HOTSWAP */
633
641 case SYS_TIMEOUT: 634 case SYS_TIMEOUT:
642 if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) 635 if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ)))
643 { 636 {