From 50000bb214f29235f5466b687e2127c5cfc27415 Mon Sep 17 00:00:00 2001 From: Jiyu Yang Date: Thu, 12 Apr 2018 20:00:37 +0800 Subject: [PATCH] Fixed mem leak of fence on 4.9.68 and newer PD#163966 Relevant kernel commits: 30cd85dd6edc86ea8d8589efb813f1fad41ef233 for v4.10 (master) 3a83421d482e7d7c6f4251dcd825548e5262c054 for v4.9.68 Change-Id: I30870fbeeaebd6e84e4a2929ac22a7d065beb20b --- .../drivers/gpu/arm/midgard/mali_kbase_sync_file.c | 10 +++++++--- .../drivers/gpu/arm/midgard/mali_kbase_sync_file.c | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bifrost/r9p0/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c b/bifrost/r9p0/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c index cb00c33..062ec00 100644 --- a/bifrost/r9p0/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c +++ b/bifrost/r9p0/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c @@ -68,10 +68,14 @@ int kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int stream_fd) if (!fence) return -ENOMEM; - /* Take an extra reference to the fence on behalf of the katom. - * This is needed because sync_file_create() will take ownership of - * one of these refs */ +#if (KERNEL_VERSION(4, 9, 67) >= LINUX_VERSION_CODE) + /* Take an extra reference to the fence on behalf of the sync_file. + * This is only needed on older kernels where sync_file_create() + * does not take its own reference. This was changed in v4.9.68, + * where sync_file_create() now takes its own reference. + */ dma_fence_get(fence); +#endif /* create a sync_file fd representing the fence */ sync_file = sync_file_create(fence); diff --git a/dvalin/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c b/dvalin/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c index 162c7b1..16d3563 100644 --- a/dvalin/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c +++ b/dvalin/kernel/drivers/gpu/arm/midgard/mali_kbase_sync_file.c @@ -73,10 +73,14 @@ int kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int stream_fd) if (!fence) return -ENOMEM; - /* Take an extra reference to the fence on behalf of the katom. - * This is needed because sync_file_create() will take ownership of - * one of these refs */ +#if (KERNEL_VERSION(4, 9, 67) >= LINUX_VERSION_CODE) + /* Take an extra reference to the fence on behalf of the sync_file. + * This is only needed on older kernels where sync_file_create() + * does not take its own reference. This was changed in v4.9.68, + * where sync_file_create() now takes its own reference. + */ dma_fence_get(fence); +#endif /* create a sync_file fd representing the fence */ sync_file = sync_file_create(fence); -- 2.20.1