display: add result check routine for getting the number of display 70/59970/1
authorTaeyoung Kim <ty317.kim@samsung.com>
Mon, 22 Feb 2016 02:21:09 +0000 (11:21 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Mon, 22 Feb 2016 02:21:09 +0000 (11:21 +0900)
- Previously, the return value check routine for getting
  the number of display was skipped. Thus the return value
  was not correct even if permission error is occurred

- Now, The return value check routine is added and thus
  the return value is correct.

Change-Id: Iac237061dcdce873423a0b31194fd67acf253857
Signed-off-by: Taeyoung Kim <ty317.kim@samsung.com>
src/common.h
src/display.c

index b747bb8..b4d398a 100644 (file)
 
 static inline int errno_to_device_error(int err)
 {
-       if (err == -EACCES)
+       switch (err) {
+       case 0:
+               return DEVICE_ERROR_NONE;
+       case -EACCES:
+       case -EPERM:
                return DEVICE_ERROR_PERMISSION_DENIED;
-       else if (err == -EBUSY)
+       case -EBUSY:
                return DEVICE_ERROR_RESOURCE_BUSY;
-       else if (err == -ENOTSUP || err == -ENODEV || err == -ENOENT)
+       case -ENOTSUP:
+       case -ENODEV:
+       case -ENOENT:
                return DEVICE_ERROR_NOT_SUPPORTED;
-       else if (err < 0)
+       default:
                return DEVICE_ERROR_OPERATION_FAILED;
-
-       return DEVICE_ERROR_NONE;
+       }
 }
 
 #endif /* __COMMON_H__ */
index ee89036..23bf350 100644 (file)
@@ -85,8 +85,11 @@ int device_display_get_max_brightness(int display_index, int *max_brightness)
        if (!max_brightness)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       if (display_cnt < 0)
-               device_display_get_numbers(&display_cnt);
+       if (display_cnt < 0) {
+               ret = device_display_get_numbers(&display_cnt);
+               if (ret != DEVICE_ERROR_NONE)
+                       return ret;
+       }
 
        if (display_index < 0 || display_index >= display_cnt)
                return DEVICE_ERROR_INVALID_PARAMETER;
@@ -114,8 +117,11 @@ int device_display_get_brightness(int display_index, int *brightness)
        if (!brightness)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       if (display_cnt < 0)
-               device_display_get_numbers(&display_cnt);
+       if (display_cnt < 0) {
+               ret = device_display_get_numbers(&display_cnt);
+               if (ret != DEVICE_ERROR_NONE)
+                       return ret;
+       }
 
        if (display_index < 0 || display_index >= display_cnt)
                return DEVICE_ERROR_INVALID_PARAMETER;
@@ -136,8 +142,11 @@ int device_display_set_brightness(int display_index, int brightness)
        char str_val[32];
        int ret, max;
 
-       if (display_cnt < 0)
-               device_display_get_numbers(&display_cnt);
+       if (display_cnt < 0) {
+               ret = device_display_get_numbers(&display_cnt);
+               if (ret != DEVICE_ERROR_NONE)
+                       return ret;
+       }
 
        if (display_index < 0 || display_index >= display_cnt)
                return DEVICE_ERROR_INVALID_PARAMETER;