aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRex Zhu <Rex.Zhu@amd.com>2015-12-29 00:56:03 -0500
committerAlex Deucher <alexander.deucher@amd.com>2016-01-08 15:39:23 -0500
commita969e163a4ac1b0cfa2dc7ab890aaa9ab092951c (patch)
treee3efd3937e624d2e96cf5e5557fb9bbd376e0867
parentc15c8d70207d467bb4312d6ac5536c101246fdc6 (diff)
drm/amd/powerplay: add powerplay valid check to avoid null point. (v2)
In case CONFIG_DRM_AMD_POWERPLAY is defined and amdgpu.powerplay=0. some functions in powrplay can also be called by DAL. and the input parameter is *adev. if just check point not NULL was not enough and will lead to NULL point error. V2: AGD: rebase on upstream Signed-off-by: Rex Zhu <Rex.Zhu@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/powerplay/amd_powerplay.c15
-rw-r--r--drivers/gpu/drm/amd/powerplay/inc/pp_instance.h3
2 files changed, 15 insertions, 3 deletions
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index db0370bd60e3..2764bd327034 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -30,6 +30,12 @@
30#include "power_state.h" 30#include "power_state.h"
31#include "eventmanager.h" 31#include "eventmanager.h"
32 32
33#define PP_CHECK(handle) \
34 do { \
35 if ((handle) == NULL || (handle)->pp_valid != PP_VALID) \
36 return -EINVAL; \
37 } while (0)
38
33static int pp_early_init(void *handle) 39static int pp_early_init(void *handle)
34{ 40{
35 return 0; 41 return 0;
@@ -537,6 +543,8 @@ static int amd_pp_instance_init(struct amd_pp_init *pp_init,
537 if (handle == NULL) 543 if (handle == NULL)
538 return -ENOMEM; 544 return -ENOMEM;
539 545
546 handle->pp_valid = PP_VALID;
547
540 ret = smum_init(pp_init, handle); 548 ret = smum_init(pp_init, handle);
541 if (ret) 549 if (ret)
542 goto fail_smum; 550 goto fail_smum;
@@ -611,8 +619,7 @@ int amd_powerplay_display_configuration_change(void *handle, const void *input)
611 struct pp_hwmgr *hwmgr; 619 struct pp_hwmgr *hwmgr;
612 const struct amd_pp_display_configuration *display_config = input; 620 const struct amd_pp_display_configuration *display_config = input;
613 621
614 if (handle == NULL) 622 PP_CHECK((struct pp_instance *)handle);
615 return -EINVAL;
616 623
617 hwmgr = ((struct pp_instance *)handle)->hwmgr; 624 hwmgr = ((struct pp_instance *)handle)->hwmgr;
618 625
@@ -625,7 +632,9 @@ int amd_powerplay_get_display_power_level(void *handle,
625{ 632{
626 struct pp_hwmgr *hwmgr; 633 struct pp_hwmgr *hwmgr;
627 634
628 if (handle == NULL || output == NULL) 635 PP_CHECK((struct pp_instance *)handle);
636
637 if (output == NULL)
629 return -EINVAL; 638 return -EINVAL;
630 639
631 hwmgr = ((struct pp_instance *)handle)->hwmgr; 640 hwmgr = ((struct pp_instance *)handle)->hwmgr;
diff --git a/drivers/gpu/drm/amd/powerplay/inc/pp_instance.h b/drivers/gpu/drm/amd/powerplay/inc/pp_instance.h
index 7b60b617dff6..4d8ed1f33de4 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/pp_instance.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/pp_instance.h
@@ -27,7 +27,10 @@
27#include "hwmgr.h" 27#include "hwmgr.h"
28#include "eventmgr.h" 28#include "eventmgr.h"
29 29
30#define PP_VALID 0x1F1F1F1F
31
30struct pp_instance { 32struct pp_instance {
33 uint32_t pp_valid;
31 struct pp_smumgr *smu_mgr; 34 struct pp_smumgr *smu_mgr;
32 struct pp_hwmgr *hwmgr; 35 struct pp_hwmgr *hwmgr;
33 struct pp_eventmgr *eventmgr; 36 struct pp_eventmgr *eventmgr;