Hi Sriram and Daniel,

On Tue, Sep 15, 2026 at 1:52 PM Sriram Sriram
<[email protected]> wrote:
>
> From: Daniel Munic <[email protected]>
>
> ext4fs_update() iterates over all block groups with a signed 16-bit
> loop counter:
>
>         short i;
>         ...
>         for (i = 0; i < fs->no_blkgrp; i++)
>
> fs->no_blkgrp is a uint32_t. On a filesystem with more than 32767
> block groups the counter cannot represent every index: incrementing
> past SHRT_MAX is signed overflow (undefined behaviour) and the
> comparison against the unsigned no_blkgrp never terminates correctly,
> so the bitmap/group-descriptor write-back loops misbehave. The mixed
> signed/unsigned comparison is also flagged by static analysis.
>
> Use u32 for the loop counter, matching the width of no_blkgrp.
>
> Signed-off-by: Daniel Munic <[email protected]>
> Signed-off-by: Sriram Sriram <[email protected]>
Reviewed-by: Tony Dinh <[email protected]>

BTW, since you are testing this ext4_write, it might be worthwhile to
see this commit:
https://github.com/u-boot/u-boot/commit/53cc4332b3b37218a7cdab8bdb953da57eec2668

Thanks,
Tony

> ---
> Changes in v2:
>  - No change, rebased onto current master.
>
>  fs/ext4/ext4_write.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
> index 1abedcede72..2fba2197c19 100644
> --- a/fs/ext4/ext4_write.c
> +++ b/fs/ext4/ext4_write.c
> @@ -67,7 +67,7 @@ static inline void ext4fs_bg_free_blocks_inc
>
>  static void ext4fs_update(void)
>  {
> -       short i;
> +       u32 i;
>         ext4fs_update_journal();
>         struct ext_filesystem *fs = get_fs();
>         struct ext2_block_group *bgd = NULL;
> --
> 2.49.0
>

Reply via email to