Skip to contentSkip to conversation

drm/amd/pm: add missing error handling in function smu_v13_0_6_allocate_dpm_context

PATCH In review Bob Zhou 2 participants 2 messages May 31, 2024

Subsystems (3)
lore
Share & tools
lore

Bob Zhou

author
#0 lore raw

PATCH v2 1/1 drm/amd/pm: add missing error handling in function smu_v13_0_6_allocate_dpm_context

Check return value to avoid null pointer dereference.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +5 -0
index 15c0aa0ad443..6b8decaf6427 100644
@@ -451,6 +451,11 @@ static int smu_v13_0_6_allocate_dpm_context(struct smu_context *smu)
 
 	smu_dpm->dpm_policies =
 		kzalloc(sizeof(struct smu_dpm_policy_ctxt), GFP_KERNEL);
+	if (!smu_dpm->dpm_policies) {
+		kfree(smu_dpm->dpm_context);
+		return -ENOMEM;
+	}
+
 	if (!(smu->adev->flags & AMD_IS_APU)) {
 		policy = &(smu_dpm->dpm_policies->policies[0]);
 
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Best Regards,
Kevin

-----Original Message-----
From: Bob Zhou <[email protected]>
Sent: Friday, May 31, 2024 4:22 PM
To: [email protected]; Wang, Yang(Kevin) <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, Bob <[email protected]>
Subject: [PATCH v2] drm/amd/pm: add missing error handling in function smu_v13_0_6_allocate_dpm_context

Check return value to avoid null pointer dereference.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +5 -0
index 15c0aa0ad443..6b8decaf6427 100644
@@ -451,6 +451,11 @@ static int smu_v13_0_6_allocate_dpm_context(struct smu_context *smu)
 
        smu_dpm->dpm_policies =
                kzalloc(sizeof(struct smu_dpm_policy_ctxt), GFP_KERNEL);
+       if (!smu_dpm->dpm_policies) {
+               kfree(smu_dpm->dpm_context);
+               return -ENOMEM;
+       }
+
        if (!(smu->adev->flags & AMD_IS_APU)) {
                policy = &(smu_dpm->dpm_policies->policies[0]);
 

--
2.34.1