Skip to content

Commit

Permalink
drm/msm/a6xx: Replace kcalloc() with kvzalloc()
Browse files Browse the repository at this point in the history
In order to reduce chance of allocation failure while capturing a6xx
gpu state, use kvzalloc() instead of kcalloc() in state_kcalloc().

Indirectly, this patch helps to fix leaking memory allocated for
gmu_debug object.

Fixes: b859f9b (drm/msm/gpu: Snapshot GMU debug buffer)
Signed-off-by: Akhil P Oommen <quic_akhilpo@quicinc.com>
Patchwork: https://patchwork.freedesktop.org/patch/505074/
Link: https://lore.kernel.org/r/20220928124830.1.I8ea24a8d586b4978823b848adde000f92f74d5c2@changeid
Signed-off-by: Rob Clark <robdclark@chromium.org>
  • Loading branch information
Akhil P Oommen authored and robclark committed Sep 30, 2022
1 parent 084b9e1 commit ec8f181
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct a6xx_state_memobj {
static void *state_kcalloc(struct a6xx_gpu_state *a6xx_state, int nr, size_t objsize)
{
struct a6xx_state_memobj *obj =
kzalloc((nr * objsize) + sizeof(*obj), GFP_KERNEL);
kvzalloc((nr * objsize) + sizeof(*obj), GFP_KERNEL);

if (!obj)
return NULL;
Expand Down Expand Up @@ -819,7 +819,7 @@ static struct msm_gpu_state_bo *a6xx_snapshot_gmu_bo(

snapshot->iova = bo->iova;
snapshot->size = bo->size;
snapshot->data = kvzalloc(snapshot->size, GFP_KERNEL);
snapshot->data = state_kcalloc(a6xx_state, 1, snapshot->size);
if (!snapshot->data)
return NULL;

Expand Down Expand Up @@ -1034,14 +1034,8 @@ static void a6xx_gpu_state_destroy(struct kref *kref)
struct a6xx_gpu_state *a6xx_state = container_of(state,
struct a6xx_gpu_state, base);

if (a6xx_state->gmu_log)
kvfree(a6xx_state->gmu_log->data);

if (a6xx_state->gmu_hfi)
kvfree(a6xx_state->gmu_hfi->data);

list_for_each_entry_safe(obj, tmp, &a6xx_state->objs, node)
kfree(obj);
kvfree(obj);

adreno_gpu_state_destroy(state);
kfree(a6xx_state);
Expand Down

0 comments on commit ec8f181

Please sign in to comment.