From 23cf76c2af5ff77255a617da20002a61bae1eed8 Mon Sep 17 00:00:00 2001 From: Tobias Diedrich Date: Tue, 29 Jun 2010 19:12:57 +0000 Subject: [PATCH] mutex_lock/unlock must be moved up a level to make the verify code in sd-as3525.c safe git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27180 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/as3525/sd-as3525.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c index 1fd10bfaee..40392b35b2 100644 --- a/firmware/target/arm/as3525/sd-as3525.c +++ b/firmware/target/arm/as3525/sd-as3525.c @@ -689,7 +689,6 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, unsigned long response; bool aligned = !((uintptr_t)buf & (CACHEALIGN_SIZE - 1)); - mutex_lock(&sd_mtx); sd_enable(true); led(true); @@ -870,14 +869,19 @@ sd_transfer_error_nodma: if (ret) /* error */ card_info[drive].initialized = 0; - mutex_unlock(&sd_mtx); return ret; } int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf) { - return sd_transfer_sectors(IF_MD2(drive,) start, count, buf, false); + int ret; + + mutex_lock(&sd_mtx); + ret = sd_transfer_sectors(IF_MD2(drive,) start, count, buf, false); + mutex_unlock(&sd_mtx); + + return ret; } int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, @@ -890,11 +894,13 @@ int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, #endif int ret; + mutex_lock(&sd_mtx); + ret = sd_transfer_sectors(IF_MD2(drive,) start, count, (void*)buf, true); #ifdef VERIFY_WRITE if (ret) /* write failed, no point in verifying */ - return ret; + goto write_error; count = saved_count; buf = saved_buf; @@ -916,6 +922,10 @@ int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, start += transfer; } #endif + +write_error: + mutex_unlock(&sd_mtx); + return ret; }