diff mbox series

staging: media: atomisp: init high & low vars

Message ID 5406825f-9b67-a59e-de62-b446ad316b96@xs4all.nl
State New
Headers show
Series staging: media: atomisp: init high & low vars | expand

Commit Message

Hans Verkuil April 19, 2023, 7:06 a.m. UTC
Fix a compiler warning:

include/linux/dev_printk.h: In function 'ov2680_probe':
include/linux/dev_printk.h:144:31: warning: 'high' may be used uninitialized [-Wmaybe-uninitialized]
  144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
      |                               ^~~~~~~~
In function 'ov2680_detect',
    inlined from 'ov2680_s_config' at drivers/staging/media/atomisp/i2c/atomisp-ov2680.c:468:8,
    inlined from 'ov2680_probe' at drivers/staging/media/atomisp/i2c/atomisp-ov2680.c:647:8:
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c:376:13: note: 'high' was declared here
  376 |         u32 high, low;
      |             ^~~~

'high' is indeed uninitialized after the ov_read_reg8() call failed, so there is no
point showing the value. Just say that the read failed. But low can also be used
uninitialized later, so just make it more robust and properly zero the high and low
variables.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---

Comments

Hans de Goede April 19, 2023, 8:20 a.m. UTC | #1
Hi,


On 4/19/23 09:06, Hans Verkuil wrote:
> Fix a compiler warning:
> 
> include/linux/dev_printk.h: In function 'ov2680_probe':
> include/linux/dev_printk.h:144:31: warning: 'high' may be used uninitialized [-Wmaybe-uninitialized]
>   144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
>       |                               ^~~~~~~~
> In function 'ov2680_detect',
>     inlined from 'ov2680_s_config' at drivers/staging/media/atomisp/i2c/atomisp-ov2680.c:468:8,
>     inlined from 'ov2680_probe' at drivers/staging/media/atomisp/i2c/atomisp-ov2680.c:647:8:
> drivers/staging/media/atomisp/i2c/atomisp-ov2680.c:376:13: note: 'high' was declared here
>   376 |         u32 high, low;
>       |             ^~~~
> 
> 'high' is indeed uninitialized after the ov_read_reg8() call failed, so there is no
> point showing the value. Just say that the read failed. But low can also be used
> uninitialized later, so just make it more robust and properly zero the high and low
> variables.
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans





> ---
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
> index 63de214916f5..c079368019e8 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
> @@ -373,7 +373,7 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd,
>  static int ov2680_detect(struct i2c_client *client)
>  {
>  	struct i2c_adapter *adapter = client->adapter;
> -	u32 high, low;
> +	u32 high = 0, low = 0;
>  	int ret;
>  	u16 id;
>  	u8 revision;
> @@ -383,7 +383,7 @@ static int ov2680_detect(struct i2c_client *client)
> 
>  	ret = ov_read_reg8(client, OV2680_SC_CMMN_CHIP_ID_H, &high);
>  	if (ret) {
> -		dev_err(&client->dev, "sensor_id_high = 0x%x\n", high);
> +		dev_err(&client->dev, "sensor_id_high read failed (%d)\n", ret);
>  		return -ENODEV;
>  	}
>  	ret = ov_read_reg8(client, OV2680_SC_CMMN_CHIP_ID_L, &low);
>
diff mbox series

Patch

diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
index 63de214916f5..c079368019e8 100644
--- a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
+++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
@@ -373,7 +373,7 @@  static int ov2680_get_fmt(struct v4l2_subdev *sd,
 static int ov2680_detect(struct i2c_client *client)
 {
 	struct i2c_adapter *adapter = client->adapter;
-	u32 high, low;
+	u32 high = 0, low = 0;
 	int ret;
 	u16 id;
 	u8 revision;
@@ -383,7 +383,7 @@  static int ov2680_detect(struct i2c_client *client)

 	ret = ov_read_reg8(client, OV2680_SC_CMMN_CHIP_ID_H, &high);
 	if (ret) {
-		dev_err(&client->dev, "sensor_id_high = 0x%x\n", high);
+		dev_err(&client->dev, "sensor_id_high read failed (%d)\n", ret);
 		return -ENODEV;
 	}
 	ret = ov_read_reg8(client, OV2680_SC_CMMN_CHIP_ID_L, &low);