Message ID | 20190404130306.13896-1-hdegoede@redhat.com |
---|---|
State | Rejected |
Headers | show |
Series | i2c: core: Fix compiler warning in i2c_generic_scl_recovery | expand |
On Thu, Apr 04, 2019 at 03:03:06PM +0200, Hans de Goede wrote: > The compiler is not smart enough to figure out that ret will always > be assiged a value in the while loop. Explicitly init ret, fixing: Wouldn't it be proper to file a bug report with your compiler then?
Hi, On 24-04-19 18:03, Wolfram Sang wrote: > On Thu, Apr 04, 2019 at 03:03:06PM +0200, Hans de Goede wrote: >> The compiler is not smart enough to figure out that ret will always >> be assiged a value in the while loop. Explicitly init ret, fixing: > > Wouldn't it be proper to file a bug report with your compiler then? Giving the complexity of the while-loop and the conditions under which ret are set, no I don't think this is a compiler bug. Note I'm seeing this with gcc-9.0.1, I've no idea why earlier gcc versions did not hit this. Regards, Hans
> Note I'm seeing this with gcc-9.0.1, I've no idea why earlier gcc > versions did not hit this. gcc (Debian 9.3.0-10) 9.3.0 currently here. I never noticed this warning. Do you still see it? Maybe it was just because of the early 9.0 version?
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 38af18645133..c480ca385ffb 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -185,7 +185,7 @@ static int i2c_generic_bus_free(struct i2c_adapter *adap) int i2c_generic_scl_recovery(struct i2c_adapter *adap) { struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; - int i = 0, scl = 1, ret; + int i = 0, scl = 1, ret = 0; if (bri->prepare_recovery) bri->prepare_recovery(adap);
The compiler is not smart enough to figure out that ret will always be assiged a value in the while loop. Explicitly init ret, fixing: drivers/i2c/i2c-core-base.c: In function ‘i2c_generic_scl_recovery’: drivers/i2c/i2c-core-base.c:235:5: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized] 235 | if (ret == -EOPNOTSUPP) | ^ Signed-off-by: Hans de Goede <hdegoede@redhat.com> --- drivers/i2c/i2c-core-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)