In _lx_nor_flash_extended_cache_enable(), the initial size check appears to compare bytes against a word count:
if ((memory) && (size < LX_NOR_SECTOR_SIZE))
{
return(LX_ERROR);
}
size is the RAM cache size in bytes, but LX_NOR_SECTOR_SIZE is defined as:
#define LX_NOR_SECTOR_SIZE (512 / sizeof(ULONG))
So it represents the number of ULONG words in a 512-byte sector, not bytes.
The rest of the function confirms this, since it converts size to words:
cache_size = size / sizeof(ULONG);
and then compares cache_size against LX_NOR_SECTOR_SIZE.
The current check rejects only sizes below 128 bytes, although it should reject sizes below one NOR sector, i.e. 512 bytes.
Suggested fix: move the cache_size calculation before the validation and check using the same unit:
/* Calculate cache size in words. */
cache_size = size / sizeof(ULONG);
/* Determine if memory was specified but with an invalid size. */
if ((memory) && (cache_size < LX_NOR_SECTOR_SIZE))
{
return(LX_ERROR);
}
In
_lx_nor_flash_extended_cache_enable(), the initial size check appears to compare bytes against a word count:sizeis the RAM cache size in bytes, butLX_NOR_SECTOR_SIZEis defined as:So it represents the number of
ULONGwords in a 512-byte sector, not bytes.The rest of the function confirms this, since it converts
sizeto words:and then compares
cache_sizeagainstLX_NOR_SECTOR_SIZE.The current check rejects only sizes below 128 bytes, although it should reject sizes below one NOR sector, i.e. 512 bytes.
Suggested fix: move the
cache_sizecalculation before the validation and check using the same unit: