Skip to content

LevelX NOR extended cache size check uses wrong unit #76

Closed

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

Activity

  1. fdesbiens commented on Jun 23, 2026

    @fdesbiens
    Contributor

    Thank you for the bug report, @miracoli. I will look into it.

  2. self-assigned this
    on Jun 23, 2026
  3. moved this to Evaluation in ThreadX Roadmapon Jun 23, 2026
  4. fdesbiens commented on Jun 26, 2026

    @fdesbiens
    Contributor

    I submitted PR #78 to address this. Your feedback is welcome, @miracoli.

    If it resolves the issue, I will merge to dev. This would ship in the Q3 2026 release.

  5. moved this from Evaluation to In review in ThreadX Roadmapon Jun 26, 2026
  6. miracoli commented on Jun 29, 2026

    @miracoli
    ContributorAuthor

    From my side, this resolves the issue. Thanks for the fast response!

  7. fdesbiens commented on Jun 30, 2026

    @fdesbiens
    Contributor

    PR #78 has been merged.

  8. moved this from In review to Done in ThreadX Roadmapon Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions