From bc2af47971270eea9d376b043eb505295c7eec0b Mon Sep 17 00:00:00 2001 From: Far Date: Fri, 22 Oct 2021 10:49:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DFATFS=E4=B8=AD?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. f_open接口在一些错误分支中未释放当前文件的锁,这会导致再次打开该文件时失败(EBUSY); 2. f_mkfs未正确初始化返回值FRESULT fr的值,导致不可预知的返回值; 3. f_fdisk循环条件错误,导致死循环; Close #I4EZEC Signed-off-by: Far --- source/ff.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/ff.c b/source/ff.c index 9d8bb74..4345b4a 100644 --- a/source/ff.c +++ b/source/ff.c @@ -3424,6 +3424,9 @@ FRESULT f_open ( fp->buf = (BYTE*) ff_memalloc(SS(fs)); /* Init sector buffer */ if (fp->buf == NULL) { res = FR_NOT_ENOUGH_CORE; +#if FF_FS_LOCK != 0 + dec_lock(fp->obj.lockid); +#endif #if FF_FS_REENTRANT LEAVE_FF(fs_bak, res); #else @@ -3484,11 +3487,11 @@ FRESULT f_open ( clst = get_fat(&fp->obj, clst); } } - - if (res != FR_OK) { - /* If the chain is occupied, Recycle the file lock ,pass out an error*/ - dec_lock(fp->obj.lockid); - } + } +#endif +#if FF_FS_LOCK != 0 + if (res != FR_OK) { + dec_lock(fp->obj.lockid); /* Ivalid lockid will be ignored */ } #endif FREE_NAMBUF(); @@ -5597,7 +5600,7 @@ FRESULT f_mkfs ( UINT n_fat, n_root, i; /* Index, Number of FATs and Number of roor dir entries */ int vol; DSTATUS ds; - FRESULT fr; + FRESULT fr = FR_OK; #if FF_MULTI_PARTITION int extended_br; int extended_pos = -1; @@ -6362,6 +6365,7 @@ FRESULT f_fdisk ( while (szt[i] != 0 && i < 4) { ptbl[i] = szt[i]; + i++; } LEAVE_MKFS(create_partition(pdrv, ptbl, 0x07, buf));