diff options
Diffstat (limited to 'firmware/target/arm/as3525/sd-as3525.c')
-rw-r--r-- | firmware/target/arm/as3525/sd-as3525.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c index c80c7f7491..ead40eac3c 100644 --- a/firmware/target/arm/as3525/sd-as3525.c +++ b/firmware/target/arm/as3525/sd-as3525.c | |||
@@ -449,21 +449,12 @@ static void sd_thread(void) | |||
449 | { | 449 | { |
450 | #ifdef HAVE_HOTSWAP | 450 | #ifdef HAVE_HOTSWAP |
451 | case SYS_HOTSWAP_INSERTED: | 451 | case SYS_HOTSWAP_INSERTED: |
452 | case SYS_HOTSWAP_EXTRACTED: | 452 | case SYS_HOTSWAP_EXTRACTED:; |
453 | { | 453 | int success = 1; |
454 | int microsd_init = 1; | ||
455 | fat_lock(); /* lock-out FAT activity first - | ||
456 | prevent deadlocking via disk_mount that | ||
457 | would cause a reverse-order attempt with | ||
458 | another thread */ | ||
459 | mutex_lock(&sd_mtx); /* lock-out card activity - direct calls | ||
460 | into driver that bypass the fat cache */ | ||
461 | 454 | ||
462 | /* We now have exclusive control of fat cache and ata */ | 455 | disk_unmount(SD_SLOT_AS3525); /* release "by force" */ |
463 | 456 | ||
464 | disk_unmount(SD_SLOT_AS3525); /* release "by force", ensure file | 457 | mutex_lock(&sd_mtx); /* lock-out card activity */ |
465 | descriptors aren't leaked and any busy | ||
466 | ones are invalid if mounting */ | ||
467 | 458 | ||
468 | /* Force card init for new card, re-init for re-inserted one or | 459 | /* Force card init for new card, re-init for re-inserted one or |
469 | * clear if the last attempt to init failed with an error. */ | 460 | * clear if the last attempt to init failed with an error. */ |
@@ -471,29 +462,32 @@ static void sd_thread(void) | |||
471 | 462 | ||
472 | if (ev.id == SYS_HOTSWAP_INSERTED) | 463 | if (ev.id == SYS_HOTSWAP_INSERTED) |
473 | { | 464 | { |
465 | success = 0; | ||
474 | sd_enable(true); | 466 | sd_enable(true); |
475 | init_pl180_controller(SD_SLOT_AS3525); | 467 | init_pl180_controller(SD_SLOT_AS3525); |
476 | microsd_init = sd_init_card(SD_SLOT_AS3525); | 468 | int rc = sd_init_card(SD_SLOT_AS3525); |
477 | if (microsd_init < 0) /* initialisation failed */ | 469 | sd_enable(false); |
478 | panicf("microSD init failed : %d", microsd_init); | 470 | if (rc >= 0) |
479 | 471 | success = 2; | |
480 | microsd_init = disk_mount(SD_SLOT_AS3525); /* 0 if fail */ | 472 | else /* initialisation failed */ |
473 | panicf("microSD init failed : %d", rc); | ||
481 | } | 474 | } |
482 | 475 | ||
476 | mutex_unlock(&sd_mtx); | ||
477 | |||
478 | if (success > 1) | ||
479 | success = disk_mount(SD_SLOT_AS3525); /* 0 if fail */ | ||
480 | |||
483 | /* | 481 | /* |
484 | * Mount succeeded, or this was an EXTRACTED event, | 482 | * Mount succeeded, or this was an EXTRACTED event, |
485 | * in both cases notify the system about the changed filesystems | 483 | * in both cases notify the system about the changed filesystems |
486 | */ | 484 | */ |
487 | if (microsd_init) | 485 | if (success) |
488 | queue_broadcast(SYS_FS_CHANGED, 0); | 486 | queue_broadcast(SYS_FS_CHANGED, 0); |
489 | 487 | ||
490 | /* Access is now safe */ | ||
491 | mutex_unlock(&sd_mtx); | ||
492 | fat_unlock(); | ||
493 | sd_enable(false); | ||
494 | } | ||
495 | break; | 488 | break; |
496 | #endif | 489 | #endif /* HAVE_HOTSWAP */ |
490 | |||
497 | case SYS_TIMEOUT: | 491 | case SYS_TIMEOUT: |
498 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) | 492 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) |
499 | { | 493 | { |