Skip to content

Commit 83d18e9

Browse files
committed
drm/msm/a6xx: Fix kvzalloc vs state_kcalloc usage
adreno_show_object() is a trap! It will re-allocate the pointer it is passed on first call, when the data is ascii85 encoded, using kvmalloc/ kvfree(). Which means the data *passed* to it must be kvmalloc'd, ie. we cannot use the state_kcalloc() helper. This partially reverts commit ec8f181 ("drm/msm/a6xx: Replace kcalloc() with kvzalloc()"), but adds the missing kvfree() to fix the memory leak that was present previously. And adds a warning comment. Fixes: ec8f181 ("drm/msm/a6xx: Replace kcalloc() with kvzalloc()") Closes: https://gitlab.freedesktop.org/drm/msm/-/issues/20 Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Chia-I Wu <[email protected]> Reviewed-by: Akhil P Oommen <[email protected]> Patchwork: https://patchwork.freedesktop.org/patch/507014/ Link: https://lore.kernel.org/r/[email protected]
1 parent 70445de commit 83d18e9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ static struct msm_gpu_state_bo *a6xx_snapshot_gmu_bo(
819819

820820
snapshot->iova = bo->iova;
821821
snapshot->size = bo->size;
822-
snapshot->data = state_kcalloc(a6xx_state, 1, snapshot->size);
822+
snapshot->data = kvzalloc(snapshot->size, GFP_KERNEL);
823823
if (!snapshot->data)
824824
return NULL;
825825

@@ -1034,6 +1034,15 @@ static void a6xx_gpu_state_destroy(struct kref *kref)
10341034
struct a6xx_gpu_state *a6xx_state = container_of(state,
10351035
struct a6xx_gpu_state, base);
10361036

1037+
if (a6xx_state->gmu_log)
1038+
kvfree(a6xx_state->gmu_log->data);
1039+
1040+
if (a6xx_state->gmu_hfi)
1041+
kvfree(a6xx_state->gmu_hfi->data);
1042+
1043+
if (a6xx_state->gmu_debug)
1044+
kvfree(a6xx_state->gmu_debug->data);
1045+
10371046
list_for_each_entry_safe(obj, tmp, &a6xx_state->objs, node)
10381047
kvfree(obj);
10391048

drivers/gpu/drm/msm/adreno/adreno_gpu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,12 @@ static char *adreno_gpu_ascii85_encode(u32 *src, size_t len)
729729
return buf;
730730
}
731731

732-
/* len is expected to be in bytes */
732+
/* len is expected to be in bytes
733+
*
734+
* WARNING: *ptr should be allocated with kvmalloc or friends. It can be free'd
735+
* with kvfree() and replaced with a newly kvmalloc'd buffer on the first call
736+
* when the unencoded raw data is encoded
737+
*/
733738
void adreno_show_object(struct drm_printer *p, void **ptr, int len,
734739
bool *encoded)
735740
{

0 commit comments

Comments
 (0)