diff mbox series

[v2] ext4: mballoc: avoid garbage value from err

Message ID 20230725043310.1227621-1-suhui@nfschina.com
State Awaiting Upstream
Headers show
Series [v2] ext4: mballoc: avoid garbage value from err | expand

Commit Message

Su Hui July 25, 2023, 4:33 a.m. UTC
clang's static analysis warning: fs/ext4/mballoc.c
line 4178, column 6, Branch condition evaluates to a garbage value.

err is uninitialized and will be judged when 'len <= 0' or
it first enters the loop while the condition "!ext4_sb_block_valid()"
is true. Although this can't make problems now, it's better to
correct it.

Signed-off-by: Su Hui <suhui@nfschina.com>
---
v2:
 - modify commit message

 fs/ext4/mballoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nick Desaulniers Aug. 1, 2023, 4:18 p.m. UTC | #1
On Mon, Jul 24, 2023 at 9:34 PM Su Hui <suhui@nfschina.com> wrote:
>
> clang's static analysis warning: fs/ext4/mballoc.c
> line 4178, column 6, Branch condition evaluates to a garbage value.
>
> err is uninitialized and will be judged when 'len <= 0' or
> it first enters the loop while the condition "!ext4_sb_block_valid()"
> is true. Although this can't make problems now, it's better to
> correct it.
>
> Signed-off-by: Su Hui <suhui@nfschina.com>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
> v2:
>  - modify commit message
>
>  fs/ext4/mballoc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 21b903fe546e..769000c970b0 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -4084,7 +4084,7 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
>         struct ext4_sb_info *sbi = EXT4_SB(sb);
>         ext4_group_t group;
>         ext4_grpblk_t blkoff;
> -       int i, err;
> +       int i, err = 0;
>         int already;
>         unsigned int clen, clen_changed, thisgrp_len;
>
> --
> 2.30.2
>
Theodore Ts'o Aug. 18, 2023, 5:05 a.m. UTC | #2
On Tue, 25 Jul 2023 12:33:11 +0800, Su Hui wrote:
> clang's static analysis warning: fs/ext4/mballoc.c
> line 4178, column 6, Branch condition evaluates to a garbage value.
> 
> err is uninitialized and will be judged when 'len <= 0' or
> it first enters the loop while the condition "!ext4_sb_block_valid()"
> is true. Although this can't make problems now, it's better to
> correct it.
> 
> [...]

Applied, thanks!

[1/1] ext4: mballoc: avoid garbage value from err
      commit: f2060a35e10fc3db2950e98f5b7f6f55ad4e4079

Best regards,
diff mbox series

Patch

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 21b903fe546e..769000c970b0 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4084,7 +4084,7 @@  void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	ext4_group_t group;
 	ext4_grpblk_t blkoff;
-	int i, err;
+	int i, err = 0;
 	int already;
 	unsigned int clen, clen_changed, thisgrp_len;