• Arnd Bergmann's avatar
    cpufreq: amd-pstate: avoid uninitialized variable use · 7cca9a98
    Arnd Bergmann authored
    The new epp support causes warnings about three separate
    but related bugs:
    
    1) failing before allocation should just return an error:
    
    drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
            if (!dev)
                ^~~~
    drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here
            return ret;
                   ^~~
    
    2) wrong variable to store return code:
    
    drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
            if (rc)
                ^~
    drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here
            return ret;
                   ^~~
    drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is always false
            if (rc)
            ^~~~~~~
    
    3) calling amd_pstate_set_epp() in cleanup path after determining
    that it should not be called:
    
    drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
            if (cpudata->epp_policy == cpudata->policy)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here
            amd_pstate_set_epp(cpudata, epp);
                                        ^~~
    
    All three are trivial to fix, but most likely there are additional bugs
    in this function when the error handling was not really tested.
    
    Fixes: ffa5096a ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors")
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Tested-by: default avatarWyes Karny <wyes.karny@amd.com>
    Reviewed-by: default avatarYuan Perry <Perry.Yuan@amd.com>
    Acked-by: default avatarHuang Rui <ray.huang@amd.com>
    Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
    7cca9a98
amd-pstate.c 33.9 KB