simplefs icon indicating copy to clipboard operation
simplefs copied to clipboard

Is the check avail >= SIMPLEFS_MAX_EXTENTS actually necessary here?

Open RoyWFHuang opened this issue 3 weeks ago • 0 comments

The purpose of this check is to prevent avail from going out of bounds, but I think it may not be necessary.

/* Validate avail index is within bounds */
if (avail >= SIMPLEFS_MAX_EXTENTS) {
    ret = -EMLINK;
    goto iput;
}

Whenever functions like "simplefs_create" are called, we already validate the maximum number of files with:

if (eblock->nr_files == SIMPLEFS_MAX_SUBFILES)

If this check passes, it means there is guaranteed to be space for creating a new object under this directory. Therefore, simplefs_get_available_ext_idx() should never return an out-of-bound value, and this boundary check appears redundant.

RoyWFHuang avatar Nov 27 '25 21:11 RoyWFHuang