Fixed NOR extended cache size validation

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Frédéric Desbiens
2026-06-26 12:13:25 -04:00
co-authored by Codex
parent 4005a425b7
commit c232f9f8e3
2 changed files with 28 additions and 9 deletions
@@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
// Some portions generated by Codex (GPT-5).
/**************************************************************************/
/**************************************************************************/
@@ -93,8 +95,11 @@ ULONG block_word;
#endif
/* Calculate cache size in words. */
cache_size = size / sizeof(ULONG);
/* Determine if memory was specified but with an invalid size (less than one NOR sector). */
if ((memory) && (size < LX_NOR_SECTOR_SIZE))
if ((memory) && (cache_size < LX_NOR_SECTOR_SIZE))
{
/* Error in memory size supplied. */
@@ -110,9 +115,6 @@ ULONG block_word;
/* Initialize the internal NOR cache. */
nor_flash -> lx_nor_flash_extended_cache_entries = 0;
/* Calculate cache size in words. */
cache_size = size/sizeof(ULONG);
/* Setup cache memory pointer. */
cache_memory = (ULONG *) memory;
@@ -317,5 +319,3 @@ ULONG block_word;
return(LX_DISABLED);
#endif
}