summaryrefslogtreecommitdiffstats
path: root/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-08-25 07:59:34 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-08-25 08:19:10 -0400
commit1b31101fdd131545b1ba0560ff67a46c702d278e (patch)
tree84edc5515421f6b2612bf11ed52993453fa325eb /firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
parent63ef81de314a29b3289ff896a29a8844c6f1607f (diff)
downloadrockbox-1b31101fdd131545b1ba0560ff67a46c702d278e.tar.gz
rockbox-1b31101fdd131545b1ba0560ff67a46c702d278e.tar.bz2
rockbox-1b31101fdd131545b1ba0560ff67a46c702d278e.zip
jz4740: Fix potential deadlock in SD init code.
There's a code path that calls sd_init_device() while we hold sd_mtx, but sd_init_device() tries to obtain the mutex while doing its work. Change-Id: I882c595e9e7cd2224b1db0d413925668628476e9
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c')
-rw-r--r--firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
index d2438655e2..116d9849cc 100644
--- a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
+++ b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
@@ -1184,13 +1184,11 @@ static int sd_select_card(void)
return 0;
}
-static int sd_init_device(void)
+static int __sd_init_device(void)
{
int retval;
struct sd_request init_req;
- mutex_lock(&sd_mtx);
-
/* Initialise card data as blank */
memset(&card, 0, sizeof(tCardInfo));
@@ -1210,7 +1208,6 @@ static int sd_init_device(void)
retval = (retval == SD_INIT_PASSED ? sd_select_card() : -1);
__cpm_stop_msc(); /* disable SD clock */
- mutex_unlock(&sd_mtx);
return retval;
}
@@ -1225,7 +1222,11 @@ int sd_init(void)
inited = true;
}
- return sd_init_device();
+ mutex_lock(&sd_mtx);
+ int ret = __sd_init_device();
+ mutex_unlock(&sd_mtx);
+
+ return ret;
}
static inline bool card_detect_target(void)
@@ -1267,7 +1268,7 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf)
if (!card_detect_target() || count == 0 || start > card.numblocks)
goto err;
- if(card.initialized == 0 && !sd_init_device())
+ if(card.initialized == 0 && !__sd_init_device())
goto err;
sd_simple_cmd(&request, SD_SEND_STATUS, card.rca, RESPONSE_R1);
@@ -1321,7 +1322,7 @@ int sd_write_sectors(IF_MV(int drive,) unsigned long start, int count, const voi
if (!card_detect_target() || count == 0 || start > card.numblocks)
goto err;
- if(card.initialized == 0 && !sd_init_device())
+ if(card.initialized == 0 && !__sd_init_device())
goto err;
sd_simple_cmd(&request, SD_SEND_STATUS, card.rca, RESPONSE_R1);