xfarray: warn against sorting arrays with identical elements

LOLLM complains about a potential underflow here if xfarray_qsort_push
is called with lo==0.  However, this isn't possible in most cases
because filesystem metadata records cannot be identical.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Assisted-by: LOLLM # finding obvious bugs
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
Darrick J. Wong 2026-09-22 23:00:44 -07:00 committed by Carlos Maiolino
parent ebd528d198
commit ddeb5fe2d8

View File

@ -682,6 +682,18 @@ xfarray_qsort_push(
return -EFSCORRUPTED;
}
/*
* Avoid the integer underflow below in (lo - 1). This shouldn't
* be possible because the pivot is the median of nine distinct
* filesystem metadata records, so at least four records will be less
* than the pivot, which means the pivot will not be in the low end of
* the range by the time we get here.
*/
if (lo == 0) {
ASSERT(lo != 0);
return -EFSCORRUPTED;
}
si->max_stack_used = max_t(uint8_t, si->max_stack_used,
si->stack_depth + 2);