a27ed1f25ed31fdf9644061d7f8d4918affea7b6
[openwrt/staging/xback.git] /
1 From 49036d4ab54259a8fa8c1511a7024ed95d68037d Mon Sep 17 00:00:00 2001
2 From: Nathan Chancellor <nathan@kernel.org>
3 Date: Mon, 31 Jan 2022 17:50:43 -0700
4 Subject: [PATCH] media: i2c: ov9281: Initialize id_msb to zero in
5 ov9281_check_sensor_id()
6
7 Clang warns:
8
9 drivers/media/i2c/ov9281.c:1132:6: warning: variable 'id_msb' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
10 if (!ret)
11 ^~~~
12 drivers/media/i2c/ov9281.c:1135:9: note: uninitialized use occurs here
13 id |= (id_msb << 8);
14 ^~~~~~
15 drivers/media/i2c/ov9281.c:1132:2: note: remove the 'if' if its condition is always true
16 if (!ret)
17 ^~~~~~~~~
18 drivers/media/i2c/ov9281.c:1127:20: note: initialize the variable 'id_msb' to silence this warning
19 u32 id = 0, id_msb;
20 ^
21 = 0
22 1 warning generated.
23
24 If the first ov9281_read_reg() call fails, id_msb will be used
25 uninitialized. However, this warning does not actually matter in
26 practice because the value of id is not used when either call to
27 ov9281_read_reg() fails, as the boolean OR will short circuit due to the
28 ret condition being checked first. Regardless, it is not good to use
29 variables uninitialized so silence the warning by initializing id_msb to
30 0, as was done with id.
31
32 Fixes: 20855581e0eb ("media: i2c: ov9281: Read chip ID via 2 reads")
33 Signed-off-by: Nathan Chancellor <nathan@kernel.org>
34 ---
35 drivers/media/i2c/ov9281.c | 2 +-
36 1 file changed, 1 insertion(+), 1 deletion(-)
37
38 --- a/drivers/media/i2c/ov9281.c
39 +++ b/drivers/media/i2c/ov9281.c
40 @@ -1124,7 +1124,7 @@ static int ov9281_check_sensor_id(struct
41 struct i2c_client *client)
42 {
43 struct device *dev = &ov9281->client->dev;
44 - u32 id = 0, id_msb;
45 + u32 id = 0, id_msb = 0;
46 int ret;
47
48 ret = ov9281_read_reg(client, OV9281_REG_CHIP_ID + 1,