media: i2c: ov9281: Initialize id_msb to zero in ov9281_check_sensor_id()
authorNathan Chancellor <nathan@kernel.org>
Tue, 1 Feb 2022 00:50:43 +0000 (17:50 -0700)
committerDom Cobley <popcornmix@gmail.com>
Mon, 21 Mar 2022 16:04:39 +0000 (16:04 +0000)
commit989d7dc9342ea14716d34c2b4f42455d8cdaff90
tree56776ed41d2a0ef5503b8056543697791cb3c1f0
parent628eedf6db11ad1df08f4a037e7e116b3796e212
media: i2c: ov9281: Initialize id_msb to zero in ov9281_check_sensor_id()

Clang warns:

  drivers/media/i2c/ov9281.c:1132:6: warning: variable 'id_msb' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
          if (!ret)
              ^~~~
  drivers/media/i2c/ov9281.c:1135:9: note: uninitialized use occurs here
          id |= (id_msb << 8);
                 ^~~~~~
  drivers/media/i2c/ov9281.c:1132:2: note: remove the 'if' if its condition is always true
          if (!ret)
          ^~~~~~~~~
  drivers/media/i2c/ov9281.c:1127:20: note: initialize the variable 'id_msb' to silence this warning
          u32 id = 0, id_msb;
                            ^
                             = 0
  1 warning generated.

If the first ov9281_read_reg() call fails, id_msb will be used
uninitialized. However, this warning does not actually matter in
practice because the value of id is not used when either call to
ov9281_read_reg() fails, as the boolean OR will short circuit due to the
ret condition being checked first. Regardless, it is not good to use
variables uninitialized so silence the warning by initializing id_msb to
0, as was done with id.

Fixes: 20855581e0eb ("media: i2c: ov9281: Read chip ID via 2 reads")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
drivers/media/i2c/ov9281.c