drm/amd/powerplay: add NULL check for vega10_ps
Subsystems (3)
PATCH 1/1 drm/amd/powerplay: add NULL check for vega10_ps
From: Gleb Markov <[email protected]>
cast_phw_vega10_power_state() can return NULL and the return result must be checked.
Add a NULL check to avoid NULL derederence.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +4 -0
@@ -3844,6 +3844,8 @@ static uint32_t vega10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)return -EINVAL ; vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return -EINVAL ;if (low)return vega10_ps->performance_levels[0 ].gfx_clock;
@@ -3866,6 +3868,8 @@ static uint32_t vega10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)return -EINVAL ; vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return -EINVAL ;if (low)return vega10_ps->performance_levels[0 ].mem_clock;
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch adds NULL checks for the Vega10 hardware manager but misses identical vulnerabilities in the SMU7 and SMU8 hardware managers. --
commit 3281774cdb4d49d848f2310e1feaba91d2dc6884
Author: Gleb Markov <[email protected]>
drm/amd/powerplay: add NULL check for vega10_ps
This patch addresses SVACE static analyzer findings by adding NULL checks for the return value of cast_phw_vega10_power_state() in the Vega10 hardware manager to prevent potential NULL pointer dereferences.
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c static uint32_t vega10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low) · line 3896
Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +2
-0@@ -3892,6 +3892,8 @@ static uint32_t vega10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)return -EINVAL ; vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return -EINVAL ;
[Severity: High]
This isn't a bug introduced by this patch, but while you are addressing this SVACE warning for Vega10, does the exact same missing NULL check pattern exist in the SMU7 and SMU8 hardware managers?
For example, in drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c:smu7_dpm_get_sclk():
smu7_ps = cast_phw_smu7_power_state(&ps->hardware); if (low) return smu7_ps->performance_levels[0].engine_clock;
And in drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c:smu8_dpm_get_sclk():
smu8_ps = cast_smu8_power_state(&ps->hardware); if (low) return smu8_ps->levels[0].engineClock;
Should identical NULL checks be added to smu7_dpm_get_sclk(), smu7_dpm_get_mclk(), smu8_dpm_get_sclk(), and smu8_dpm_patch_boot_state() to ensure a complete fix across the subsystem and avoid kernel panics if the power state magic number check fails?
Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +0
-0if (low)return vega10_ps->performance_levels[0 ].gfx_clock;
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1