Commit 0f3561a4 authored by Anand Balagopalakrishnan's avatar Anand Balagopalakrishnan
Browse files

km: fix GEM handle memory leak



When memory handles are mapped, a dummy GEM handle is created so that it can be
accepted by DRM. However, when the memory handle is unmaped, there is no
corresponding delete of  the GEM handle.

Given that each GEM handle is 4K bytes, this will result in a memory leak that
will result in application crash over time. This is not catastrophic to the
system since DRM/GEM core will cleanup the GEM handles allocated as part of the
proces when it exit.

This patch addresses the GEM handle leak in SGX driver.
Signed-off-by: default avatarAnand Balagopalakrishnan <anandb@ti.com>
parent 3b475f4c
......@@ -198,6 +198,7 @@ struct _LinuxMemArea {
#if defined(SUPPORT_DRI_DRM_EXTERNAL)
IMG_HANDLE buf; /* external buffer handle, like a GEM or ION buffer */
IMG_UINT32 uiHandle; /* GEM handle */
#endif /* SUPPORT_DRI_DRM_EXTERNAL */
};
......
......@@ -517,9 +517,8 @@ PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc =
(PVRSRV_ENV_PER_PROCESS_DATA *)PVRSRVProcessPrivateData(psPerProc);
struct drm_gem_object *buf = NULL;
IMG_UINT32 uiHandle, *puiHandle;
IMG_UINT32 *puiHandle;
IMG_UINT32 ret;
puiHandle = &uiHandle;
#endif /* SUPPORT_DRI_DRM_EXTERNAL */
LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
......@@ -539,6 +538,7 @@ PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
}
psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
puiHandle = &psLinuxMemArea->uiHandle;
/* Sparse mappings have to ask the BM for the virtual size */
if (psLinuxMemArea->hBMHandle)
......@@ -715,6 +715,10 @@ PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
IMG_HANDLE hOSMemHandle;
PVRSRV_ERROR eError;
IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
#if defined(SUPPORT_DRI_DRM_EXTERNAL)
PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc =
(PVRSRV_ENV_PER_PROCESS_DATA *)PVRSRVProcessPrivateData(psPerProc);
#endif /* SUPPORT_DRI_DRM_EXTERNAL */
LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
......@@ -734,6 +738,13 @@ PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
#if defined(SUPPORT_DRI_DRM_EXTERNAL)
if (psLinuxMemArea->uiHandle) {
drm_gem_handle_delete(psEnvPerProc->file, psLinuxMemArea->uiHandle);
psLinuxMemArea->uiHandle = 0;
}
#endif
psOffsetStruct = FindOffsetStructByPID(psLinuxMemArea, ui32PID);
if (psOffsetStruct)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment