bu5hm4n pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=093846aaea3da28f2227f8c300ee807edd5c1ff4

commit 093846aaea3da28f2227f8c300ee807edd5c1ff4
Author: Marcel Hollerbach <marcel-hollerb...@t-online.de>
Date:   Mon Jan 11 21:43:12 2016 +0100

    ecore_drm: check if device is already opened before open and free
    
    check if fd is -1 before opening a device, so a device cannot be opened
    twice.
    
    Also check if fd is != -1 before closing it.
---
 src/lib/ecore_drm/ecore_drm_device.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/lib/ecore_drm/ecore_drm_device.c 
b/src/lib/ecore_drm/ecore_drm_device.c
index 5376dbd..1b7fc8b 100644
--- a/src/lib/ecore_drm/ecore_drm_device.c
+++ b/src/lib/ecore_drm/ecore_drm_device.c
@@ -237,6 +237,7 @@ cont:
 
    if ((dev = calloc(1, sizeof(Ecore_Drm_Device))))
      {
+        dev->drm.fd = -1;
         dev->drm.name = eeze_udev_syspath_get_devpath(device);
         dev->drm.path = eina_stringshare_add(device);
 
@@ -314,8 +315,15 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
    /* check for valid device */
    if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
 
+   /* check if device is already opened */
+   if (dev->drm.fd != -1)
+     {
+        ERR("Device is already opened");
+        return EINA_FALSE;
+     }
+
    /* DRM device node is needed immediately to keep going. */
-   dev->drm.fd = 
+   dev->drm.fd =
      _ecore_drm_launcher_device_open_no_pending(dev->drm.name, O_RDWR);
    if (dev->drm.fd < 0) return EINA_FALSE;
 
@@ -382,12 +390,15 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
    return EINA_TRUE;
 }
 
-EAPI Eina_Bool 
+EAPI Eina_Bool
 ecore_drm_device_close(Ecore_Drm_Device *dev)
 {
    /* check for valid device */
    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
 
+   /* check if device is opened */
+   if (dev->drm.fd == -1) return EINA_FALSE;
+
    /* delete udev watch */
    if (dev->watch) eeze_udev_watch_del(dev->watch);
 

-- 


Reply via email to