aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmarinder Bindra2013-09-25 05:37:33 -0500
committerGerrit Code Review2013-09-27 11:20:22 -0500
commit30cf86853f5cf6bc838f2b56ca441cc348bedb38 (patch)
tree8ec1f344f63ece4e1b914f67dae21f4256455c5e
parent9cd39120edafb7a4c755f63d815adc18f5d455f9 (diff)
downloadrepo-libdce-30cf86853f5cf6bc838f2b56ca441cc348bedb38.tar.gz
repo-libdce-30cf86853f5cf6bc838f2b56ca441cc348bedb38.tar.xz
repo-libdce-30cf86853f5cf6bc838f2b56ca441cc348bedb38.zip
Add check for ownership for file descriptor
Currently, the dce_deinit function deletes the file descriptor(fd) that it uses for allocation of the buffers even if it has not created it. This adds a check where it only deletes the fd only when the ownership of fd is with libdce else it only deletes th device which it uses. Also, add a check where the dce_set_fd sets the fd only if the drm device fd is not already set to avoid memory leak. Change-Id: Ie5e23f06a5d171f2c06f4bebb64b040915e71153 Signed-off-by: Amarinder Bindra <a-bindra@ti.com>
-rw-r--r--libdce_linux.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libdce_linux.c b/libdce_linux.c
index 39a03e0..2eeb1bd 100644
--- a/libdce_linux.c
+++ b/libdce_linux.c
@@ -46,6 +46,7 @@
46#define INVALID_DRM_FD (-1) 46#define INVALID_DRM_FD (-1)
47 47
48int OmapDrm_FD = INVALID_DRM_FD; 48int OmapDrm_FD = INVALID_DRM_FD;
49int bDrmOpenedByDce = FALSE;
49struct omap_device *OmapDev = NULL; 50struct omap_device *OmapDev = NULL;
50extern MmRpc_Handle MmRpcHandle; 51extern MmRpc_Handle MmRpcHandle;
51 52
@@ -60,6 +61,7 @@ void *dce_init(void)
60 DEBUG("Open omapdrm device"); 61 DEBUG("Open omapdrm device");
61 OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00"); 62 OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00");
62 _ASSERT(OmapDrm_FD > 0, DCE_EOMAPDRM_FAIL); 63 _ASSERT(OmapDrm_FD > 0, DCE_EOMAPDRM_FAIL);
64 bDrmOpenedByDce = TRUE;
63 } 65 }
64 OmapDev = omap_device_new(OmapDrm_FD); 66 OmapDev = omap_device_new(OmapDrm_FD);
65 _ASSERT(OmapDev != NULL, DCE_EOMAPDRM_FAIL); 67 _ASSERT(OmapDev != NULL, DCE_EOMAPDRM_FAIL);
@@ -72,7 +74,10 @@ void dce_deinit(void *dev)
72{ 74{
73 omap_device_del(dev); 75 omap_device_del(dev);
74 dev = NULL; 76 dev = NULL;
75 close(OmapDrm_FD); 77 if (bDrmOpenedByDce == TRUE) {
78 close(OmapDrm_FD);
79 bDrmOpenedByDce = FALSE;
80 }
76 OmapDrm_FD = INVALID_DRM_FD; 81 OmapDrm_FD = INVALID_DRM_FD;
77 82
78 return; 83 return;
@@ -131,7 +136,12 @@ EXIT:
131/* Incase of X11 or Wayland the fd can be shared to libdce using this call */ 136/* Incase of X11 or Wayland the fd can be shared to libdce using this call */
132void dce_set_fd(int dce_fd) 137void dce_set_fd(int dce_fd)
133{ 138{
134 OmapDrm_FD = dce_fd; 139 if (OmapDrm_FD == INVALID_DRM_FD) {
140 OmapDrm_FD = dce_fd;
141 }
142 else {
143 DEBUG("Cannot set the fd, omapdrm device fd is already set");
144 }
135} 145}
136 146
137int dce_get_fd(void) 147int dce_get_fd(void)