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]
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.
Patch sent: https://lore.kernel.org/lkml/[email protected]/
Another fix accepted: https://git.kernel.org/davem/net/c/1f5d861f7fefa971b2c6e766f77932c86419a319