ecore_drm: check if device is already opened before open and free
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>
Mon, 11 Jan 2016 20:43:12 +0000 (21:43 +0100)
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>
Wed, 13 Jan 2016 17:51:49 +0000 (18:51 +0100)
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

index 5376dbd..1b7fc8b 100644 (file)
@@ -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);