summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c')
-rw-r--r--firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
index 9c0d1982ad..0e74444cf3 100644
--- a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
+++ b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
@@ -26,7 +26,6 @@
26#include "ata_idle_notify.h" 26#include "ata_idle_notify.h"
27#include "ata-sd-target.h" 27#include "ata-sd-target.h"
28#include "disk.h" 28#include "disk.h"
29#include "fat.h"
30#include "led.h" 29#include "led.h"
31#include "sdmmc.h" 30#include "sdmmc.h"
32#include "logf.h" 31#include "logf.h"
@@ -1467,34 +1466,28 @@ static void sd_thread(void)
1467 { 1466 {
1468#ifdef HAVE_HOTSWAP 1467#ifdef HAVE_HOTSWAP
1469 case SYS_HOTSWAP_INSERTED: 1468 case SYS_HOTSWAP_INSERTED:
1470 case SYS_HOTSWAP_EXTRACTED: 1469 case SYS_HOTSWAP_EXTRACTED:;
1471 fat_lock(); /* lock-out FAT activity first - 1470 int success = 1;
1472 prevent deadlocking via disk_mount that
1473 would cause a reverse-order attempt with
1474 another thread */
1475 mutex_lock(&sd_mtx); /* lock-out card activity - direct calls
1476 into driver that bypass the fat cache */
1477 1471
1478 /* We now have exclusive control of fat cache and ata */ 1472 disk_unmount(sd_drive_nr); /* release "by force" */
1479 1473
1480 disk_unmount(sd_drive_nr); /* release "by force", ensure file 1474 mutex_lock(&sd_mtx); /* lock-out card activity */
1481 descriptors aren't leaked and any busy
1482 ones are invalid if mounting */
1483 1475
1484 /* Force card init for new card, re-init for re-inserted one or 1476 /* Force card init for new card, re-init for re-inserted one or
1485 * clear if the last attempt to init failed with an error. */ 1477 * clear if the last attempt to init failed with an error. */
1486 card.initialized = 0; 1478 card.initialized = 0;
1487 1479
1480 mutex_unlock(&sd_mtx);
1481
1488 if(ev.id == SYS_HOTSWAP_INSERTED) 1482 if(ev.id == SYS_HOTSWAP_INSERTED)
1489 disk_mount(sd_drive_nr); 1483 success = disk_mount(sd_drive_nr); /* 0 if fail */
1490 1484
1491 queue_broadcast(SYS_FS_CHANGED, 0); 1485 if(success)
1486 queue_broadcast(SYS_FS_CHANGED, 0);
1492 1487
1493 /* Access is now safe */
1494 mutex_unlock(&sd_mtx);
1495 fat_unlock();
1496 break; 1488 break;
1497#endif 1489#endif /* HAVE_HOTSWAP */
1490
1498 case SYS_TIMEOUT: 1491 case SYS_TIMEOUT:
1499 if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) 1492 if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ)))
1500 idle_notified = false; 1493 idle_notified = false;