VFS/LittleFS: Incorrect cache size validation causes error when default cache size /lookaside buffer size usage is expected #82918
Labels
bug
The issue is a bug, or the PR is fixing a bug
priority: medium
Medium impact/importance bug
Regression
Something, which was working, does not anymore
Milestone
Describe the bug
Commit 09574e6 has introduced cache and lookaside buffer validation that is supposed to error out in case when cache size is not aligned to device block size.
The problem with validation is that is directly tries to compare LittleFS instance stored sizes which may have value of 0 at this point; the value 0 in instance is possible as LittleFS initialization contains mechanism that defaults the instance value to system wide setting passed as Kconfig value.
The problem here is that during validation, the instance value is cached into test variable and corrected if 0:
zephyr/subsys/fs/littlefs_fs.c
Lines 780 to 790 in 7c4abb1
but check for validity once again tests against not yet modified instance value:
zephyr/subsys/fs/littlefs_fs.c
Lines 849 to 861 in 7c4abb1
since the
new_cache_size
is calculated fromblock_size
it will always be > 0; it has already been established that instance value can be 0, to pick default, but it has not yet been corrected, but thecache_size
is already corrected in lines 780-790.So the test here should check if
cache_size
/lookahead_size
are requesting at least what is calculated from block size.To Reproduce
It is enough to set cache-size parameter in DTS LittleFS instance or set
cache_size
oflittlefs_cfg
, while defining LittleFS data forfs_mount
, to 0 to immediate see initialization error.Expected behavior
Error should only appear in case when set cache size, either directly or default, is not enough to cover device block size.
Impact
Default LittleFS cache and lookaside buffer does not work.
Environment (please complete the following information):
Additional context
Affects 4.0.0.
No proper tests for default values to detect the problem.
The text was updated successfully, but these errors were encountered: