Skip to content

Dubious offset calculation in lfs_alloc_reset #484

Open
@gtaska

Description

@gtaska

The code for lfs_alloc_reset is:

// Invalidate the lookahead buffer. This is done during mounting and
// failed traversals
static void lfs_alloc_reset(lfs_t *lfs) {
    lfs->free.off = lfs->seed % lfs->cfg->block_size;
    lfs->free.size = 0;
    lfs->free.i = 0;
    lfs_alloc_ack(lfs);
}

In this code, lfs->free.off is initialized with a range-bound version of lfs->seed - however it is bounded based on the configured block_size. Everywhere else that uses/updates lfs->free.off bounds it based on block_count (which makes more sense, as you are trying to find an index such that 0 <= index < block_count).

I don't think that this is necessarily going to cause immediate issues, as everywhere else it is used it appears to be subject to another modulus operation, however in certain configurations where block_size is small compared to block_count this may bias the wear leveling.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions