diff options
Diffstat (limited to 'firmware/target/arm/tcc780x')
-rw-r--r-- | firmware/target/arm/tcc780x/sd-tcc780x.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/firmware/target/arm/tcc780x/sd-tcc780x.c b/firmware/target/arm/tcc780x/sd-tcc780x.c index 55ae4e7c70..b7abea8be4 100644 --- a/firmware/target/arm/tcc780x/sd-tcc780x.c +++ b/firmware/target/arm/tcc780x/sd-tcc780x.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "led.h" | 28 | #include "led.h" |
29 | #include "thread.h" | 29 | #include "thread.h" |
30 | #include "disk.h" | 30 | #include "disk.h" |
31 | #include "fat.h" | ||
32 | #include "ata_idle_notify.h" | 31 | #include "ata_idle_notify.h" |
33 | #include "usb.h" | 32 | #include "usb.h" |
34 | 33 | ||
@@ -657,35 +656,30 @@ static void sd_thread(void) | |||
657 | { | 656 | { |
658 | #ifdef HAVE_HOTSWAP | 657 | #ifdef HAVE_HOTSWAP |
659 | case SYS_HOTSWAP_INSERTED: | 658 | case SYS_HOTSWAP_INSERTED: |
660 | case SYS_HOTSWAP_EXTRACTED: | 659 | case SYS_HOTSWAP_EXTRACTED:; |
661 | fat_lock(); /* lock-out FAT activity first - | 660 | int success = 1; |
662 | prevent deadlocking via disk_mount that | 661 | |
663 | would cause a reverse-order attempt with | 662 | /* Release "by force" */ |
664 | another thread */ | ||
665 | mutex_lock(&sd_mtx); /* lock-out card activity - direct calls | ||
666 | into driver that bypass the fat cache */ | ||
667 | |||
668 | /* We now have exclusive control of fat cache and ata */ | ||
669 | |||
670 | /* Release "by force", ensure file descriptors aren't leaked and | ||
671 | any busy ones are invalid if mounting */ | ||
672 | disk_unmount(sd_first_drive + CARD_NUM_SLOT); | 663 | disk_unmount(sd_first_drive + CARD_NUM_SLOT); |
673 | 664 | ||
665 | mutex_lock(&sd_mtx); /* lock-out card activity */ | ||
666 | |||
674 | /* Force card init for new card, re-init for re-inserted one or | 667 | /* Force card init for new card, re-init for re-inserted one or |
675 | * clear if the last attempt to init failed with an error. */ | 668 | * clear if the last attempt to init failed with an error. */ |
676 | card_info[CARD_NUM_SLOT].initialized = 0; | 669 | card_info[CARD_NUM_SLOT].initialized = 0; |
677 | sd_status[CARD_NUM_SLOT].retry = 0; | 670 | sd_status[CARD_NUM_SLOT].retry = 0; |
678 | 671 | ||
672 | mutex_unlock(&sd_mtx); | ||
673 | |||
679 | if (ev.id == SYS_HOTSWAP_INSERTED) | 674 | if (ev.id == SYS_HOTSWAP_INSERTED) |
680 | disk_mount(sd_first_drive + CARD_NUM_SLOT); | 675 | success = disk_mount(sd_first_drive + CARD_NUM_SLOT); |
681 | 676 | ||
682 | queue_broadcast(SYS_FS_CHANGED, 0); | 677 | if (success) |
678 | queue_broadcast(SYS_FS_CHANGED, 0); | ||
683 | 679 | ||
684 | /* Access is now safe */ | ||
685 | mutex_unlock(&sd_mtx); | ||
686 | fat_unlock(); | ||
687 | break; | 680 | break; |
688 | #endif | 681 | #endif /* HAVE_HOTSWAP */ |
682 | |||
689 | case SYS_TIMEOUT: | 683 | case SYS_TIMEOUT: |
690 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) | 684 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) |
691 | { | 685 | { |