gcc-9: don’t warn about uninitialized variable [Linux 4.19.66]

This Linux kernel change "gcc-9: don’t warn about uninitialized variable" is included in the Linux 4.19.66 release. This change is authored by Linus Torvalds <torvalds [at] linux-foundation.org> on Wed May 1 11:07:40 2019 -0700. The commit for this change in Linux stable tree is a152a7b (patch) which is from upstream commit cf67690. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream cf67690.

gcc-9: don't warn about uninitialized variable

commit cf676908846a06443fa5e6724ca3f5dd7460eca1 upstream.

I'm not sure what made gcc warn about this code now.  The 'ret' variable
does end up initialized in all cases, but it's definitely not obvious,
so the compiler is quite reasonable to warn about this.

So just add initialization to make it all much more obvious both to
compilers and to humans.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/i2c/i2c-core-base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 5b0e1d9..1de10e5 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);

Leave a Reply

Your email address will not be published. Required fields are marked *