Skip to content

Commit 41855a8

Browse files
Tom Rixalexdeucher
authored andcommitted
drm/radeon: fix double free
clang static analysis flags this error drivers/gpu/drm/radeon/ci_dpm.c:5652:9: warning: Use of memory after it is freed [unix.Malloc] kfree(rdev->pm.dpm.ps[i].ps_priv); ^~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/radeon/ci_dpm.c:5654:2: warning: Attempt to free released memory [unix.Malloc] kfree(rdev->pm.dpm.ps); ^~~~~~~~~~~~~~~~~~~~~~ problem is reported in ci_dpm_fini, with these code blocks. for (i = 0; i < rdev->pm.dpm.num_ps; i++) { kfree(rdev->pm.dpm.ps[i].ps_priv); } kfree(rdev->pm.dpm.ps); The first free happens in ci_parse_power_table where it cleans up locally on a failure. ci_dpm_fini also does a cleanup. ret = ci_parse_power_table(rdev); if (ret) { ci_dpm_fini(rdev); return ret; } So remove the cleanup in ci_parse_power_table and move the num_ps calculation to inside the loop so ci_dpm_fini will know how many array elements to free. Fixes: cc8dbbb ("drm/radeon: add dpm support for CI dGPUs (v2)") Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected]
1 parent 3b2e973 commit 41855a8

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/gpu/drm/radeon/ci_dpm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5563,6 +5563,7 @@ static int ci_parse_power_table(struct radeon_device *rdev)
55635563
if (!rdev->pm.dpm.ps)
55645564
return -ENOMEM;
55655565
power_state_offset = (u8 *)state_array->states;
5566+
rdev->pm.dpm.num_ps = 0;
55665567
for (i = 0; i < state_array->ucNumEntries; i++) {
55675568
u8 *idx;
55685569
power_state = (union pplib_power_state *)power_state_offset;
@@ -5572,10 +5573,8 @@ static int ci_parse_power_table(struct radeon_device *rdev)
55725573
if (!rdev->pm.power_state[i].clock_info)
55735574
return -EINVAL;
55745575
ps = kzalloc(sizeof(struct ci_ps), GFP_KERNEL);
5575-
if (ps == NULL) {
5576-
kfree(rdev->pm.dpm.ps);
5576+
if (ps == NULL)
55775577
return -ENOMEM;
5578-
}
55795578
rdev->pm.dpm.ps[i].ps_priv = ps;
55805579
ci_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
55815580
non_clock_info,
@@ -5597,8 +5596,8 @@ static int ci_parse_power_table(struct radeon_device *rdev)
55975596
k++;
55985597
}
55995598
power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
5599+
rdev->pm.dpm.num_ps = i + 1;
56005600
}
5601-
rdev->pm.dpm.num_ps = state_array->ucNumEntries;
56025601

56035602
/* fill in the vce power states */
56045603
for (i = 0; i < RADEON_MAX_VCE_LEVELS; i++) {

0 commit comments

Comments
 (0)