From eba81ccc5b7d59ddb453a061eebef50fc64b4f7c Mon Sep 17 00:00:00 2001 From: brandonchuang Date: Mon, 13 Mar 2017 17:26:29 +0800 Subject: [PATCH] [as5912-54x] simplify the code for onlp_file_read_int --- .../onlp/builds/src/module/src/fani.c | 32 ++++++++----------- .../onlp/builds/src/module/src/ledi.c | 8 ++--- .../onlp/builds/src/module/src/platform_lib.c | 6 ++-- .../onlp/builds/src/module/src/platform_lib.h | 2 +- .../onlp/builds/src/module/src/psui.c | 6 ++-- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/fani.c index 636852b5..9eb030ce 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/fani.c @@ -86,14 +86,13 @@ onlp_fan_info_t finfo[] = { static int _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) { - int value; + int value, ret; char path[64] = {0}; /* get fan present status */ - sprintf(path, "%s""fan%d_present", FAN_BOARD_PATH, fid); - - if (onlp_file_read_int(&value, path) < 0) { + ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid); + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } @@ -106,9 +105,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) { + ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid); + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } @@ -120,9 +118,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) { + ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid); + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } @@ -132,9 +129,8 @@ _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) { + ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } @@ -142,9 +138,8 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) /* get rear fan speed */ - sprintf(path, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); - - if (onlp_file_read_int(&value, path) < 0) { + ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } @@ -157,9 +152,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) { + ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/ledi.c index 9a690725..af58607f 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/ledi.c @@ -170,8 +170,6 @@ int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) { int lid, value; - char path[64] = {0}; - VALIDATE(id); lid = ONLP_OID_ID_GET(id); @@ -180,10 +178,8 @@ 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) { + DEBUG_PRINT("Unable to read status from file (%s)", leds[lid]); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.c index ea006c7f..b14867bd 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.c @@ -163,13 +163,13 @@ int psu_ym2651y_pmbus_info_get(int id, char *node, int *value) *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) { + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.h index 1b320ce0..24242bfb 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/platform_lib.h @@ -80,7 +80,7 @@ enum onlp_thermal_id THERMAL_1_ON_PSU2, }; -#define DEBUG_MODE 1 +#define DEBUG_MODE 0 #if (DEBUG_MODE == 1) #define DEBUG_PRINT(fmt, args...) \ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/psui.c index 61d65ac6..6da5aa58 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54x/onlp/builds/src/module/src/psui.c @@ -49,13 +49,13 @@ psu_status_info_get(int id, char *node, int *value) *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) { + if (ret < 0) { AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; }