Re: [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()

From: David Howells
Date: Fri Apr 11 2025 - 11:36:18 EST


Zijun Hu <zijun_hu@xxxxxxxxxx> wrote:

> fs_name() has @index as unsigned int, so there is underflow risk for
> operation '@index--'.
>
> Fix by breaking the for loop when '@index == 0' which is also more proper
> than '@index <= 0' for unsigned integer comparison.

There isn't really a risk. The list walked by "tmp" and the checks that this
is or is not NULL will prevent a problem.

I also feel that breaking out of the loop with "<= 0" - even if the variable
is unsigned - is safer, on the off chance that someone in the future changes
the signedness of the variable.

David