From 30bac038fa280ae6b0ca60564cccb843bfebc2bd Mon Sep 17 00:00:00 2001 From: Djordje Nedic Date: Fri, 3 Jan 2025 16:22:05 +0100 Subject: [PATCH] fs: littlefs: Fix lookahead buffer sizing The lookahead buffer is a bitmap containing info on free blocks and does not have a minimum size or an alignment requirement. This fixes the arbitrary 4 * block_size requirement for block devices and fixes Kconfig documentation to remove a reference to nonexistent 8 byte alignment requirement. Signed-off-by: Djordje Nedic --- subsys/fs/Kconfig.littlefs | 3 +-- subsys/fs/littlefs_fs.c | 9 +-------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/subsys/fs/Kconfig.littlefs b/subsys/fs/Kconfig.littlefs index bef620ed715..048e921f62b 100644 --- a/subsys/fs/Kconfig.littlefs +++ b/subsys/fs/Kconfig.littlefs @@ -56,8 +56,7 @@ config FS_LITTLEFS_LOOKAHEAD_SIZE help A larger lookahead buffer increases the number of blocks found during an allocation pass. The lookahead buffer is stored as a - compact bitmap, so each byte of RAM can track 8 blocks. Must - be a multiple of 8. + compact bitmap, so each byte of RAM can track 8 blocks. config FS_LITTLEFS_BLOCK_CYCLES int "Number of erase cycles before moving data to another block" diff --git a/subsys/fs/littlefs_fs.c b/subsys/fs/littlefs_fs.c index 36ab00c6033..b65523c6b34 100644 --- a/subsys/fs/littlefs_fs.c +++ b/subsys/fs/littlefs_fs.c @@ -844,8 +844,6 @@ static int littlefs_init_cfg(struct fs_littlefs *fs, int flags) lcp->context = fs->backend; /* Set the validated/defaulted values. */ if (littlefs_on_blkdev(flags)) { - lfs_size_t new_lookahead_size = block_size * 4; - lcp->read = lfs_api_read_blk; lcp->prog = lfs_api_prog_blk; lcp->erase = lfs_api_erase_blk; @@ -859,12 +857,7 @@ static int littlefs_init_cfg(struct fs_littlefs *fs, int flags) } lcp->cache_size = ROUND_DOWN(cache_size, block_size); - if (lookahead_size < new_lookahead_size) { - LOG_ERR("Configured lookahead size is too small: %d < %d", - lookahead_size, new_lookahead_size); - return -ENOMEM; - } - lcp->lookahead_size = new_lookahead_size; + lcp->lookahead_size = lookahead_size; lcp->sync = lfs_api_sync_blk;