From 18c9cdae4606eb8b5d2caf0028fd649df9c43939 Mon Sep 17 00:00:00 2001 From: brandonchuang Date: Tue, 14 Mar 2017 10:30:41 +0800 Subject: [PATCH] [as5822-54x] simplify the code for onlp_file_read_int --- .../onlp/builds/src/module/src/fani.c | 39 +++++++------------ .../onlp/builds/src/module/src/ledi.c | 9 +---- .../onlp/builds/src/module/src/platform_lib.c | 9 ++--- .../onlp/builds/src/module/src/psui.c | 8 ++-- 4 files changed, 21 insertions(+), 44 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/fani.c index 6d8b50c6..16c1bf20 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/fani.c @@ -81,15 +81,12 @@ onlp_fan_info_t finfo[] = { static int _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) { - int value; - char path[64] = {0}; + int value, ret; /* get fan present status */ - sprintf(path, "%s""fan%d_present", FAN_BOARD_PATH, fid); - - if (onlp_file_read_int(&value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; } @@ -101,10 +98,8 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) /* get fan fault status (turn on when any one fails) */ - sprintf(path, "%s""fan%d_fault", FAN_BOARD_PATH, fid); - - if (onlp_file_read_int(&value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; } @@ -115,10 +110,8 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) /* get fan direction (both : the same) */ - sprintf(path, "%s""fan%d_direction", FAN_BOARD_PATH, fid); - - if (onlp_file_read_int(&value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; } @@ -127,20 +120,16 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) /* get front fan speed */ - sprintf(path, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); - - if (onlp_file_read_int(&value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; } info->rpm = value; /* get rear fan speed */ - sprintf(path, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); - - if (onlp_file_read_int(&value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; } @@ -152,10 +141,8 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) /* get speed percentage from rpm */ - sprintf(path, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); - - if (onlp_file_read_int(&value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/ledi.c index b6cf8f3a..4a0c5d41 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/ledi.c @@ -169,9 +169,7 @@ onlp_ledi_init(void) int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) { - int lid, value; - char path[64] = {0}; - + int lid, value; VALIDATE(id); lid = ONLP_OID_ID_GET(id); @@ -180,10 +178,7 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) *info = linfo[ONLP_OID_ID_GET(id)]; /* Get LED mode */ - sprintf(path, LED_FORMAT, leds[lid]); - - if (onlp_file_read_int(&value, path) < 0) { - DEBUG_PRINT("Unable to read status from file (%s)", path); + if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) { return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/platform_lib.c index 569671c5..fc7450b3 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/platform_lib.c @@ -166,19 +166,16 @@ psu_type_t get_psu_type(int id, char* modelname, int modelname_len) int psu_ym2401_pmbus_info_get(int id, char *node, int *value) { int ret = 0; - char path[PSU_NODE_MAX_PATH_LEN] = {0}; - *value = 0; if (PSU1_ID == id) { - sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + ret = onlp_file_read_int(value, "%s%s", PSU1_AC_PMBUS_PREFIX, node); } else { - sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + ret = onlp_file_read_int(value, "%s%s", PSU2_AC_PMBUS_PREFIX, node); } - if (onlp_file_read_int(value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/psui.c index 7ba1c53d..741ec596 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/psui.c @@ -44,19 +44,17 @@ static int psu_status_info_get(int id, char *node, int *value) { int ret = 0; - char path[PSU_NODE_MAX_PATH_LEN] = {0}; *value = 0; if (PSU1_ID == id) { - sprintf(path, "%s%s", PSU1_AC_HWMON_PREFIX, node); + ret = onlp_file_read_int(value, "%s%s", PSU1_AC_HWMON_PREFIX, node); } else if (PSU2_ID == id) { - sprintf(path, "%s%s", PSU2_AC_HWMON_PREFIX, node); + ret = onlp_file_read_int(value, "%s%s", PSU2_AC_HWMON_PREFIX, node); } - if (onlp_file_read_int(value, path) < 0) { - AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + if (ret < 0) { return ONLP_STATUS_E_INTERNAL; }