• Nathan Chancellor's avatar
    net: stmmac: Avoid sometimes uninitialized Clang warnings · df103170
    Nathan Chancellor authored
    When building with -Wsometimes-uninitialized, Clang warns:
    
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:495:3: warning: variable 'ns' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:495:3: warning: variable 'ns' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:532:3: warning: variable 'ns' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:532:3: warning: variable 'ns' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:741:3: warning: variable 'sec_inc' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:741:3: warning: variable 'sec_inc' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
    
    Clang is concerned with the use of stmmac_do_void_callback (which
    stmmac_get_timestamp and stmmac_config_sub_second_increment wrap),
    as it may fail to initialize these values if the if condition was ever
    false (meaning the callbacks don't exist). It's not wrong because the
    callbacks (get_timestamp and config_sub_second_increment respectively)
    are the ones that initialize the variables. While it's unlikely that the
    callbacks are ever going to disappear and make that condition false, we
    can easily avoid this warning by zero initialize the variables.
    
    Link: https://github.com/ClangBuiltLinux/linux/issues/384Suggested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
    Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
    Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    df103170
stmmac_main.c 127 KB