Skip to contentSkip to conversation

media: ov9650: avoid maybe-uninitialized warnings

PATCH In review Arnd Bergmann 3 participants 4 messages Sep 26, 2018 – Sep 27, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: ov9650: avoid maybe-uninitialized warnings

The regmap change causes multiple warnings like

drivers/media/i2c/ov9650.c: In function 'ov965x_g_volatile_ctrl':
drivers/media/i2c/ov9650.c:889:29: error: 'reg2' may be used uninitialized in this function [-Werror=maybe-uninitialized]
exposure = ((reg2 & 0x3f) << 10) | (reg1 << 2) |

              ~~~~~~~~~~~~~~~^~~~~~

It is apparently hard for the compiler to see here if ov965x_read() returned successfully or not. Besides, we have a v4l2_dbg() statement that prints an uninitialized value if regmap_read() fails.

Adding an 'else' clause avoids the ambiguity.

Fixes 361f3803adfe ("media: ov9650: use SCCB regmap")
---
 drivers/media/i2c/ov9650.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov9650.c +2 -0
index 3c9e6798d14b..77944da31de1 100644
@@ -433,6 +433,8 @@ static int ov965x_read(struct ov965x *ov965x, u8 addr, u8 *val)
 	ret = regmap_read(ov965x->regmap, addr, &buf);
 	if (!ret)
 		*val = buf;
+        else
+                *val = -1;
 
 	v4l2_dbg(2, debug, &ov965x->sd, "%s: 0x%02x @ 0x%02x. (%d)\n",
 		 __func__, *val, addr, ret);
Signature · 1 line
2.18.0
reviewer Reviewed-by on v1 1/1
#1 lore raw

2018年9月26日(水) 21:51 Arnd Bergmann <[email protected]>:

Quoted 8 lines

The regmap change causes multiple warnings like

drivers/media/i2c/ov9650.c: In function 'ov965x_g_volatile_ctrl':
drivers/media/i2c/ov9650.c:889:29: error: 'reg2' may be used uninitialized in this function [-Werror=maybe-uninitialized]
exposure = ((reg2 & 0x3f) << 10) | (reg1 << 2) |

              ~~~~~~~~~~~~~~~^~~~~~
Quoted 8 lines

It is apparently hard for the compiler to see here if ov965x_read() returned successfully or not. Besides, we have a v4l2_dbg() statement that prints an uninitialized value if regmap_read() fails.

Adding an 'else' clause avoids the ambiguity.

Fixes 361f3803adfe ("media: ov9650: use SCCB regmap")

Looks good.

Quoted 20 lines
---
 drivers/media/i2c/ov9650.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov9650.c +2 -1
index 3c9e6798d14b..77944da31de1 100644
@@ -433,6 +433,8 @@ static int ov965x_read(struct ov965x *ov965x, u8 addr, u8 *val)
        ret = regmap_read(ov965x->regmap, addr, &buf);
        if (!ret)
                *val = buf;
+        else
+                *val = -1;
 
        v4l2_dbg(2, debug, &ov965x->sd, "%s: 0x%02x @ 0x%02x. (%d)\n",
                 __func__, *val, addr, ret);
--

2.18.0

maintainer
#2 lore raw
In reply to Arnd Bergmann

Hi Arnd,

Quoted 5 lines · Arnd Bergmann

The regmap change causes multiple warnings like

drivers/media/i2c/ov9650.c: In function 'ov965x_g_volatile_ctrl':
drivers/media/i2c/ov9650.c:889:29: error: 'reg2' may be used uninitialized in this function [-Werror=maybe-uninitialized]
exposure = ((reg2 & 0x3f) << 10) | (reg1 << 2) |

Quoted 7 lines
              ~~~~~~~~~~~~~~~^~~~~~

It is apparently hard for the compiler to see here if ov965x_read() returned successfully or not. Besides, we have a v4l2_dbg() statement that prints an uninitialized value if regmap_read() fails.

Adding an 'else' clause avoids the ambiguity.

Thanks!

I'm not sure what happened here but the two lines use spaces for indentation. I've replaced those with tabs.

Quoted 20 lines
Fixes 361f3803adfe ("media: ov9650: use SCCB regmap")
---
 drivers/media/i2c/ov9650.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov9650.c +2 -0
index 3c9e6798d14b..77944da31de1 100644
@@ -433,6 +433,8 @@ static int ov965x_read(struct ov965x *ov965x, u8 addr, u8 *val)
 	ret = regmap_read(ov965x->regmap, addr, &buf);
 	if (!ret)
 		*val = buf;
+        else
+                *val = -1;
 
 	v4l2_dbg(2, debug, &ov965x->sd, "%s: 0x%02x @ 0x%02x. (%d)\n",
 		 __func__, *val, addr, ret);
Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
#3 lore raw
Quoted 15 lines · Sakari Ailus

Hi Arnd,

Quoted 11 lines · Arnd Bergmann

The regmap change causes multiple warnings like

drivers/media/i2c/ov9650.c: In function 'ov965x_g_volatile_ctrl':
drivers/media/i2c/ov9650.c:889:29: error: 'reg2' may be used uninitialized in this function [-Werror=maybe-uninitialized]
exposure = ((reg2 & 0x3f) << 10) | (reg1 << 2) |

              ~~~~~~~~~~~~~~~^~~~~~

It is apparently hard for the compiler to see here if ov965x_read() returned successfully or not. Besides, we have a v4l2_dbg() statement that prints an uninitialized value if regmap_read() fails.

Quoted 6 lines
Quoted 1 line

Adding an 'else' clause avoids the ambiguity.

Thanks!

I'm not sure what happened here but the two lines use spaces for indentation. I've replaced those with tabs.

Thanks a lot, that was clearly what I had intended to send.

Arnd