Skip to content

LevelX NOR extended cache size check uses wrong unit #76

@miracoli

Description

@miracoli

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions