Linux: -Wsometimes-uninitialized in drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Created on 26 Feb 2019  路  5Comments  路  Source: ClangBuiltLinux/linux

from #381

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:495:3: error: variable 'ns' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:495:3: error: variable 'ns' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:532:3: error: variable 'ns' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:532:3: error: variable 'ns' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:741:3: error: variable 'sec_inc' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:741:3: error: variable 'sec_inc' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
-Wsometimes-uninitialized [ARCH] arm32 [BUG] linux [FIXED][LINUX] 5.1

All 5 comments

Seems like the use of stmmac_get_timestamp is problematic in the first 4 cases, and stmmac_config_sub_second_increment in the second. Also, line numbers of the above are off due to them coming from linux-next, but I still see the issue in mainline.

stmmac_get_timestamp expands to stmmac_do_void_callback, which invokes a function it's passed (get_timestamp) and forwards the rest of the args to that function.

The issue is that the check in stmmac_do_void_callback if ever false would not call the callback, and potentially not initialize the variable.

Doesn't hurt to just initialize the variable ns.

sec_inc has the same problem in stmmac_config_sub_second_increment which expands to stmmac_do_void_callback again but invokes the passed callback config_sub_second_increment which may or may not get called. Almost every other local variable in stmmac_config_sub_second_increment is zero initialized, except sec_inc.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tpimh picture tpimh  路  5Comments

nickdesaulniers picture nickdesaulniers  路  4Comments

tpgxyz picture tpgxyz  路  4Comments

nickdesaulniers picture nickdesaulniers  路  3Comments

tpgxyz picture tpgxyz  路  4Comments