From b28e031e64517b294558ca696ad03e35bf5eedd0 Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Mon, 22 Feb 2016 11:21:09 +0900 Subject: [PATCH] display: add result check routine for getting the number of display - 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 --- src/common.h | 17 +++++++++++------ src/display.c | 21 +++++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/common.h b/src/common.h index b747bb8..b4d398a 100644 --- a/src/common.h +++ b/src/common.h @@ -37,16 +37,21 @@ 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__ */ diff --git a/src/display.c b/src/display.c index ee89036..23bf350 100644 --- a/src/display.c +++ b/src/display.c @@ -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; -- 2.7.4