Skip to content

Commit 3d6955b

Browse files
Navidemgregkh
authored andcommitted
drm/etnaviv: fix ref count leak via pm_runtime_get_sync
[ Upstream commit c5d5a32 ] in etnaviv_gpu_submit, etnaviv_gpu_recover_hang, etnaviv_gpu_debugfs, and etnaviv_gpu_init the call to pm_runtime_get_sync increments the counter even in case of failure, leading to incorrect ref count. In case of failure, decrement the ref count before returning. Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6569387 commit 3d6955b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

drivers/gpu/drm/etnaviv/etnaviv_gpu.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
694694
ret = pm_runtime_get_sync(gpu->dev);
695695
if (ret < 0) {
696696
dev_err(gpu->dev, "Failed to enable GPU power domain\n");
697-
return ret;
697+
goto pm_put;
698698
}
699699

700700
etnaviv_hw_identify(gpu);
@@ -808,6 +808,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
808808
gpu->mmu = NULL;
809809
fail:
810810
pm_runtime_mark_last_busy(gpu->dev);
811+
pm_put:
811812
pm_runtime_put_autosuspend(gpu->dev);
812813

813814
return ret;
@@ -848,7 +849,7 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m)
848849

849850
ret = pm_runtime_get_sync(gpu->dev);
850851
if (ret < 0)
851-
return ret;
852+
goto pm_put;
852853

853854
dma_lo = gpu_read(gpu, VIVS_FE_DMA_LOW);
854855
dma_hi = gpu_read(gpu, VIVS_FE_DMA_HIGH);
@@ -971,6 +972,7 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m)
971972
ret = 0;
972973

973974
pm_runtime_mark_last_busy(gpu->dev);
975+
pm_put:
974976
pm_runtime_put_autosuspend(gpu->dev);
975977

976978
return ret;
@@ -985,7 +987,7 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
985987
dev_err(gpu->dev, "recover hung GPU!\n");
986988

987989
if (pm_runtime_get_sync(gpu->dev) < 0)
988-
return;
990+
goto pm_put;
989991

990992
mutex_lock(&gpu->lock);
991993

@@ -1005,6 +1007,7 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
10051007

10061008
mutex_unlock(&gpu->lock);
10071009
pm_runtime_mark_last_busy(gpu->dev);
1010+
pm_put:
10081011
pm_runtime_put_autosuspend(gpu->dev);
10091012
}
10101013

@@ -1278,8 +1281,10 @@ struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit)
12781281

12791282
if (!submit->runtime_resumed) {
12801283
ret = pm_runtime_get_sync(gpu->dev);
1281-
if (ret < 0)
1284+
if (ret < 0) {
1285+
pm_runtime_put_noidle(gpu->dev);
12821286
return NULL;
1287+
}
12831288
submit->runtime_resumed = true;
12841289
}
12851290

@@ -1296,6 +1301,7 @@ struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit)
12961301
ret = event_alloc(gpu, nr_events, event);
12971302
if (ret) {
12981303
DRM_ERROR("no free events\n");
1304+
pm_runtime_put_noidle(gpu->dev);
12991305
return NULL;
13001306
}
13011307

0 commit comments

Comments
 (0)