discomfitor pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=3d71a10891c31de9c667f15f8f37371a5664f759

commit 3d71a10891c31de9c667f15f8f37371a5664f759
Author: Mike Blumenkrantz <zm...@osg.samsung.com>
Date:   Fri Apr 24 12:51:34 2015 -0400

    ecore-drm: add safety checks to all EAPI functions
---
 src/lib/ecore_drm/ecore_drm_device.c   | 11 ++++++-----
 src/lib/ecore_drm/ecore_drm_evdev.c    |  3 ++-
 src/lib/ecore_drm/ecore_drm_fb.c       |  4 ++++
 src/lib/ecore_drm/ecore_drm_inputs.c   |  1 +
 src/lib/ecore_drm/ecore_drm_launcher.c |  2 ++
 src/lib/ecore_drm/ecore_drm_output.c   | 18 +++++++++++++-----
 src/lib/ecore_drm/ecore_drm_sprites.c  |  8 +++++---
 src/lib/ecore_drm/ecore_drm_tty.c      | 10 +++++-----
 8 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/src/lib/ecore_drm/ecore_drm_device.c 
b/src/lib/ecore_drm/ecore_drm_device.c
index f0908e2..9919486 100644
--- a/src/lib/ecore_drm/ecore_drm_device.c
+++ b/src/lib/ecore_drm/ecore_drm_device.c
@@ -334,7 +334,7 @@ EAPI Eina_Bool
 ecore_drm_device_close(Ecore_Drm_Device *dev)
 {
    /* check for valid device */
-   if (!dev) return EINA_FALSE;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
 
    /* delete udev watch */
    if (dev->watch) eeze_udev_watch_del(dev->watch);
@@ -404,7 +404,7 @@ ecore_drm_device_master_drop(Ecore_Drm_Device *dev)
 EAPI int 
 ecore_drm_device_fd_get(Ecore_Drm_Device *dev)
 {
-   if (!dev) return -1;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
    return dev->drm.fd;
 }
 
@@ -412,7 +412,7 @@ EAPI void
 ecore_drm_device_window_set(Ecore_Drm_Device *dev, unsigned int window)
 {
    /* check for valid device */
-   if ((!dev) || (dev->drm.fd < 0)) return;
+   EINA_SAFETY_ON_TRUE_RETURN((!dev) || (dev->drm.fd < 0));
 
    dev->window = window;
 }
@@ -421,7 +421,7 @@ EAPI const char *
 ecore_drm_device_name_get(Ecore_Drm_Device *dev)
 {
    /* check for valid device */
-   if ((!dev) || (dev->drm.fd < 0)) return NULL;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((!dev) || (dev->drm.fd < 0), NULL);
 
    return dev->drm.name;
 }
@@ -437,7 +437,7 @@ ecore_drm_device_pointer_xy_get(Ecore_Drm_Device *dev, int 
*x, int *y)
    if (y) *y = 0;
 
    /* check for valid device */
-   if ((!dev) || (dev->drm.fd < 0)) return;
+   EINA_SAFETY_ON_TRUE_RETURN((!dev) || (dev->drm.fd < 0));
 
    EINA_LIST_FOREACH(dev->seats, l, seat)
      {
@@ -508,6 +508,7 @@ ecore_drm_device_output_find(Ecore_Drm_Device *dev, int x, 
int y)
    Eina_List *l;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, NULL);
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((x < 0) || (y < 0), NULL);
 
    EINA_LIST_FOREACH(dev->outputs, l, output)
      {
diff --git a/src/lib/ecore_drm/ecore_drm_evdev.c 
b/src/lib/ecore_drm/ecore_drm_evdev.c
index 04275fd..f56e372 100644
--- a/src/lib/ecore_drm/ecore_drm_evdev.c
+++ b/src/lib/ecore_drm/ecore_drm_evdev.c
@@ -879,7 +879,8 @@ ecore_drm_inputs_device_axis_size_set(Ecore_Drm_Evdev 
*edev, int w, int h)
    const char *vals;
    enum libinput_config_status status;
 
-   if ((w == 0) || (h == 0)) return;
+   EINA_SAFETY_ON_NULL_RETURN(edev);
+   EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
 
    if ((!libinput_device_config_calibration_has_matrix(edev->device)) || 
        (libinput_device_config_calibration_get_default_matrix(edev->device, 
cal) != 0))
diff --git a/src/lib/ecore_drm/ecore_drm_fb.c b/src/lib/ecore_drm/ecore_drm_fb.c
index a3e3b37..982f962 100644
--- a/src/lib/ecore_drm/ecore_drm_fb.c
+++ b/src/lib/ecore_drm/ecore_drm_fb.c
@@ -55,6 +55,8 @@ ecore_drm_fb_create(Ecore_Drm_Device *dev, int width, int 
height)
    struct drm_mode_destroy_dumb darg;
    struct drm_mode_map_dumb marg;
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, NULL);
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((width < 1) || (height < 1), NULL);
    if (!(fb = calloc(1, sizeof(Ecore_Drm_Fb)))) return NULL;
 
    memset(&carg, 0, sizeof(struct drm_mode_create_dumb));
@@ -139,6 +141,8 @@ EAPI void
 ecore_drm_fb_dirty(Ecore_Drm_Fb *fb, Eina_Rectangle *rects, unsigned int count)
 {
    EINA_SAFETY_ON_NULL_RETURN(fb);
+   EINA_SAFETY_ON_NULL_RETURN(rects);
+   EINA_SAFETY_ON_TRUE_RETURN(!count);
 
 #ifdef DRM_MODE_FEATURE_DIRTYFB
    drmModeClip *clip;
diff --git a/src/lib/ecore_drm/ecore_drm_inputs.c 
b/src/lib/ecore_drm/ecore_drm_inputs.c
index bfd237c..1b517b6 100644
--- a/src/lib/ecore_drm/ecore_drm_inputs.c
+++ b/src/lib/ecore_drm/ecore_drm_inputs.c
@@ -292,6 +292,7 @@ ecore_drm_inputs_destroy(Ecore_Drm_Device *dev)
    Ecore_Drm_Seat *seat;
    Ecore_Drm_Evdev *edev;
 
+   EINA_SAFETY_ON_NULL_RETURN(dev);
    EINA_LIST_FREE(dev->seats, seat)
      {
         EINA_LIST_FREE(seat->devices, edev)
diff --git a/src/lib/ecore_drm/ecore_drm_launcher.c 
b/src/lib/ecore_drm/ecore_drm_launcher.c
index 8166fe4..e66918a 100644
--- a/src/lib/ecore_drm/ecore_drm_launcher.c
+++ b/src/lib/ecore_drm/ecore_drm_launcher.c
@@ -56,6 +56,7 @@ _ecore_drm_launcher_device_flags_set(int fd, int flags)
 EAPI Eina_Bool 
 ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
 {
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
    /* try to connect to logind */
    if (!(logind = _ecore_drm_logind_connect(dev)))
      {
@@ -86,6 +87,7 @@ ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
 EAPI void 
 ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev)
 {
+   EINA_SAFETY_ON_NULL_RETURN(dev);
    if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
    dev->tty.switch_hdlr = NULL;
 
diff --git a/src/lib/ecore_drm/ecore_drm_output.c 
b/src/lib/ecore_drm/ecore_drm_output.c
index dbcd088..b564f10 100644
--- a/src/lib/ecore_drm/ecore_drm_output.c
+++ b/src/lib/ecore_drm/ecore_drm_output.c
@@ -721,6 +721,7 @@ ecore_drm_outputs_create(Ecore_Drm_Device *dev)
    int i = 0, x = 0, y = 0;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
+   EINA_SAFETY_ON_TRUE_RETURN_VAL(dev->drm.fd < 0, EINA_FALSE);
 
    /* DBG("Create outputs for %d", dev->drm.fd); */
 
@@ -788,7 +789,7 @@ ecore_drm_output_free(Ecore_Drm_Output *output)
 EAPI void 
 ecore_drm_output_cursor_size_set(Ecore_Drm_Output *output, int handle, int w, 
int h)
 {
-   if (!output) return;
+   EINA_SAFETY_ON_NULL_RETURN(output);
    drmModeSetCursor(output->dev->drm.fd, output->crtc_id, handle, w, h);
 }
 
@@ -800,9 +801,10 @@ ecore_drm_output_enable(Ecore_Drm_Output *output)
    int x = 0, y = 0;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(output, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(output->dev, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(output->current_mode, EINA_FALSE);
 
-   if (!(dev = output->dev)) return EINA_FALSE;
+   dev = output->dev;
 
    output->enabled = EINA_TRUE;
    if (!dev->current)
@@ -847,6 +849,8 @@ ecore_drm_output_disable(Ecore_Drm_Output *output)
 EAPI void 
 ecore_drm_output_fb_release(Ecore_Drm_Output *output, Ecore_Drm_Fb *fb)
 {
+   EINA_SAFETY_ON_NULL_RETURN(output);
+   EINA_SAFETY_ON_NULL_RETURN(fb);
    _ecore_drm_output_fb_release(output, fb);
 }
 
@@ -859,9 +863,10 @@ ecore_drm_output_repaint(Ecore_Drm_Output *output)
    int ret = 0;
 
    EINA_SAFETY_ON_NULL_RETURN(output);
+   EINA_SAFETY_ON_NULL_RETURN(output->dev);
    EINA_SAFETY_ON_TRUE_RETURN(output->pending_destroy);
 
-   if (!(dev = output->dev)) return;
+   dev = output->dev;
 
    /* DBG("Output Repaint: %d %d", output->crtc_id, output->conn_id); */
 
@@ -942,7 +947,7 @@ ecore_drm_output_size_get(Ecore_Drm_Device *dev, int 
output, int *w, int *h)
 
    if (w) *w = 0;
    if (h) *h = 0;
-   if (!dev) return;
+   EINA_SAFETY_ON_NULL_RETURN(dev);
 
    if (!(fb = drmModeGetFB(dev->drm.fd, output))) return;
    if (w) *w = fb->width;
@@ -961,7 +966,7 @@ ecore_drm_outputs_geometry_get(Ecore_Drm_Device *dev, int 
*x, int *y, int *w, in
    if (y) *y = 0;
    if (w) *w = 0;
    if (h) *h = 0;
-   if (!dev) return;
+   EINA_SAFETY_ON_NULL_RETURN(dev);
 
    EINA_LIST_FOREACH(dev->outputs, l, output)
      {
@@ -1032,6 +1037,7 @@ EAPI void
 ecore_drm_output_dpms_set(Ecore_Drm_Output *output, int level)
 {
    EINA_SAFETY_ON_NULL_RETURN(output);
+   EINA_SAFETY_ON_NULL_RETURN(output->dev);
    EINA_SAFETY_ON_NULL_RETURN(output->dpms);
 
    drmModeConnectorSetProperty(output->dev->drm.fd, output->conn_id,
@@ -1042,6 +1048,7 @@ EAPI void
 ecore_drm_output_gamma_set(Ecore_Drm_Output *output, uint16_t size, uint16_t 
*r, uint16_t *g, uint16_t *b)
 {
    EINA_SAFETY_ON_NULL_RETURN(output);
+   EINA_SAFETY_ON_NULL_RETURN(output->dev);
    EINA_SAFETY_ON_NULL_RETURN(output->crtc);
 
    if (output->gamma != size) return;
@@ -1065,6 +1072,7 @@ ecore_drm_output_crtc_buffer_get(Ecore_Drm_Output *output)
    unsigned int id = 0;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(output, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(output->dev, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(output->crtc, 0);
 
    if (!(crtc = drmModeGetCrtc(output->dev->drm.fd, output->crtc_id)))
diff --git a/src/lib/ecore_drm/ecore_drm_sprites.c 
b/src/lib/ecore_drm/ecore_drm_sprites.c
index ee9d909..d3fa71d 100644
--- a/src/lib/ecore_drm/ecore_drm_sprites.c
+++ b/src/lib/ecore_drm/ecore_drm_sprites.c
@@ -21,7 +21,7 @@ ecore_drm_sprites_create(Ecore_Drm_Device *dev)
    unsigned int i = 0;
 
    /* check for valid device */
-   if ((!dev) || (dev->drm.fd < 0)) return EINA_FALSE;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((!dev) || (dev->drm.fd < 0), EINA_FALSE);
 
    /* get plane resources */
    if (!(res = drmModeGetPlaneResources(dev->drm.fd))) return EINA_FALSE;
@@ -66,7 +66,7 @@ ecore_drm_sprites_destroy(Ecore_Drm_Device *dev)
    Ecore_Drm_Sprite *sprite;
 
    /* check for valid device */
-   if (!dev) return;
+   EINA_SAFETY_ON_NULL_RETURN(dev);
 
    EINA_LIST_FREE(dev->sprites, sprite)
      {
@@ -82,7 +82,7 @@ ecore_drm_sprites_destroy(Ecore_Drm_Device *dev)
 EAPI void 
 ecore_drm_sprites_fb_set(Ecore_Drm_Sprite *sprite, int fb_id, int flags)
 {
-   if ((!sprite) || (!sprite->output)) return;
+   EINA_SAFETY_ON_TRUE_RETURN((!sprite) || (!sprite->output));
 
    if (fb_id)
      {
@@ -106,6 +106,8 @@ ecore_drm_sprites_crtc_supported(Ecore_Drm_Output *output, 
unsigned int supporte
    Ecore_Drm_Device *dev;
    unsigned int c = 0;
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(output, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(output->dev, EINA_FALSE);
    dev = output->dev;
 
    for (c = 0; c < dev->crtc_count; c++)
diff --git a/src/lib/ecore_drm/ecore_drm_tty.c 
b/src/lib/ecore_drm/ecore_drm_tty.c
index e7f394d..b21773d 100644
--- a/src/lib/ecore_drm/ecore_drm_tty.c
+++ b/src/lib/ecore_drm/ecore_drm_tty.c
@@ -135,7 +135,7 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
    char tty[32] = "<stdin>";
 
    /* check for valid device */
-   if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((!dev) || (!dev->drm.name), EINA_FALSE);
 
    /* assign default tty fd of -1 */
    dev->tty.fd = -1;
@@ -226,7 +226,7 @@ EAPI Eina_Bool
 ecore_drm_tty_close(Ecore_Drm_Device *dev)
 {
    /* check for valid device */
-   if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((!dev) || (!dev->drm.name), EINA_FALSE);
 
    _ecore_drm_tty_restore(dev);
 
@@ -247,7 +247,7 @@ EAPI Eina_Bool
 ecore_drm_tty_release(Ecore_Drm_Device *dev)
 {
    /* check for valid device */
-   if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((!dev) || (!dev->drm.name) || (dev->tty.fd < 
0), EINA_FALSE);
 
    /* send ioctl for vt release */
    if (ioctl(dev->tty.fd, VT_RELDISP, 1) < 0) 
@@ -263,7 +263,7 @@ EAPI Eina_Bool
 ecore_drm_tty_acquire(Ecore_Drm_Device *dev)
 {
    /* check for valid device */
-   if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((!dev) || (!dev->drm.name) || (dev->tty.fd < 
0), EINA_FALSE);
 
    /* send ioctl for vt acquire */
    if (ioctl(dev->tty.fd, VT_RELDISP, VT_ACKACQ) < 0) 
@@ -279,7 +279,7 @@ EAPI int
 ecore_drm_tty_get(Ecore_Drm_Device *dev)
 {
    /* check for valid device */
-   if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return -1;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL((!dev) || (!dev->drm.name) || (dev->tty.fd < 
0), -1);
 
    return dev->tty.fd;
 }

-- 


Reply via email to