From facc8399f26803651d9a26c28ac2ab974eb3aa50 Mon Sep 17 00:00:00 2001 From: Ivano Bono <82436387+IvanoBono@users.noreply.github.com> Date: Wed, 7 Jul 2021 08:45:04 +0200 Subject: [PATCH 1/2] code optimization removed duplicate condition (line 5050) removed 3 unused increment in functions (line 651-676) --- source/ff.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/ff.c b/source/ff.c index cbdf685..71a6f16 100644 --- a/source/ff.c +++ b/source/ff.c @@ -652,7 +652,7 @@ static QWORD ld_qword (const BYTE* ptr) /* Load an 8-byte little-endian word */ static void st_word (BYTE* ptr, WORD val) /* Store a 2-byte word in little-endian */ { *ptr++ = (BYTE)val; val >>= 8; - *ptr++ = (BYTE)val; + *ptr = (BYTE)val; } static void st_dword (BYTE* ptr, DWORD val) /* Store a 4-byte word in little-endian */ @@ -660,7 +660,7 @@ static void st_dword (BYTE* ptr, DWORD val) /* Store a 4-byte word in little-end *ptr++ = (BYTE)val; val >>= 8; *ptr++ = (BYTE)val; val >>= 8; *ptr++ = (BYTE)val; val >>= 8; - *ptr++ = (BYTE)val; + *ptr = (BYTE)val; } #if FF_FS_EXFAT @@ -673,7 +673,7 @@ static void st_qword (BYTE* ptr, QWORD val) /* Store an 8-byte word in little-en *ptr++ = (BYTE)val; val >>= 8; *ptr++ = (BYTE)val; val >>= 8; *ptr++ = (BYTE)val; val >>= 8; - *ptr++ = (BYTE)val; + *ptr = (BYTE)val; } #endif #endif /* !FF_FS_READONLY */ @@ -5047,9 +5047,9 @@ FRESULT f_mkdir ( dj.dir[DIR_Attr] = AM_DIR; /* Attribute */ fs->wflag = 1; } - if (res == FR_OK) { + //removed duplicate condition (res == FR_OK) res = sync_fs(fs); - } + } else { remove_chain(&sobj, dcl, 0); /* Could not register, remove the allocated cluster */ } From 2310e304853a0c393bceb3ab7ec9d7fe620214f9 Mon Sep 17 00:00:00 2001 From: Ivano Bono <82436387+IvanoBono@users.noreply.github.com> Date: Wed, 7 Jul 2021 08:54:22 +0200 Subject: [PATCH 2/2] minor change minor change to avoid compiler warning --- source/ff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/ff.c b/source/ff.c index 71a6f16..f67f988 100644 --- a/source/ff.c +++ b/source/ff.c @@ -1910,7 +1910,7 @@ static int pick_lfn ( /* 1:succeeded, 0:buffer overflow or invalid LFN entry */ } } - if (dir[LDIR_Ord] & LLEF && wc != 0) { /* Put terminator if it is the last LFN part and not terminated */ + if ((dir[LDIR_Ord] & LLEF) && wc != 0) { /* Put terminator if it is the last LFN part and not terminated */ if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */ lfnbuf[i] = 0; }