drm/amd/powerplay: fix various dereferences of a pointer before it is null checked
authorColin Ian King <colin.king@canonical.com>
Thu, 12 Dec 2019 18:16:57 +0000 (18:16 +0000)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 18 Dec 2019 21:09:05 +0000 (16:09 -0500)
There are several occurrances of the pointer hwmgr being dereferenced
before it is null checked.  Fix these by performing the dereference
of hwmgr after it has been null checked.

Addresses-Coverity: ("Dereference before null check")
Fixes: c9ffa427db34e6 ("drm/amd/powerplay: enable pp one vf mode for vega10")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/amd_powerplay.c
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c

index 5087d6bdba6095b0bbb7e23d7c979eabb9d9167b..322c2015d3a06a4ba19b11df3cb3485faf129f0f 100644 (file)
@@ -275,12 +275,12 @@ static int pp_dpm_load_fw(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (!hwmgr->not_vf)
-               return 0;
-
        if (!hwmgr || !hwmgr->smumgr_funcs || !hwmgr->smumgr_funcs->start_smu)
                return -EINVAL;
 
+       if (!hwmgr->not_vf)
+               return 0;
+
        if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
                pr_err("fw load failed\n");
                return -EINVAL;
index e2b82c9029489af5f9950258c182965d30422e72..f48fdc7f0382ea99b897d6a885e0a41b62e17749 100644 (file)
@@ -282,10 +282,7 @@ err:
 
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 {
-       if (!hwmgr->not_vf)
-               return 0;
-
-       if (!hwmgr || !hwmgr->pm_en)
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->not_vf)
                return 0;
 
        phm_stop_thermal_controller(hwmgr);
@@ -305,10 +302,7 @@ int hwmgr_suspend(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (!hwmgr->not_vf)
-               return 0;
-
-       if (!hwmgr || !hwmgr->pm_en)
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->not_vf)
                return 0;
 
        phm_disable_smc_firmware_ctf(hwmgr);
@@ -327,13 +321,10 @@ int hwmgr_resume(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (!hwmgr->not_vf)
-               return 0;
-
        if (!hwmgr)
                return -EINVAL;
 
-       if (!hwmgr->pm_en)
+       if (!hwmgr->not_vf || !hwmgr->pm_en)
                return 0;
 
        ret = phm_setup_asic(hwmgr);