From 6bb72f2a715e4cd739f7ad0e67062a24e6cfc107 Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Tue, 4 Apr 2017 01:07:10 +0300 Subject: [PATCH] Use the new search API to improve compatibility between kernels. --- .../onlp/builds/src/module/src/thermali.c | 45 +++++-------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/thermali.c b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/thermali.c index 7d9efa1e..fe8cf354 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/thermali.c @@ -25,12 +25,11 @@ ***********************************************************/ #include #include +#include #include #include #include "platform_lib.h" -#define prefix_path "/sys/bus/i2c/devices/" - #define VALIDATE(_id) \ do { \ if(!ONLP_OID_IS_THERMAL(_id)) { \ @@ -38,17 +37,6 @@ } \ } while(0) -#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \ - DEBUG_PRINT("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \ - if ((fd = open(fullpath, O_RDONLY)) == -1) \ - return ONLP_STATUS_E_INTERNAL; \ - if ((len = read(fd, r_data, nbytes)) <= 0){ \ - close(fd); \ - return ONLP_STATUS_E_INTERNAL;} \ - DEBUG_PRINT("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \ - if (close(fd) == -1) \ - return ONLP_STATUS_E_INTERNAL - enum onlp_thermal_id { THERMAL_RESERVED = 0, @@ -61,16 +49,16 @@ enum onlp_thermal_id THERMAL_1_ON_PSU2, }; -static char last_path[][30] = /* must map with onlp_thermal_id */ +static char* devfiles__[] = /* must map with onlp_thermal_id */ { "reserved", - "3-0048/temp1_input", - "3-0049/temp1_input", - "3-004a/temp1_input", - "15-004c/temp1_input", - "15-004c/temp2_input", - "10-0058/psu_temp1_input", - "11-005b/psu_temp1_input", + "/sys/bus/i2c/devices/3-0048*temp1_input", + "/sys/bus/i2c/devices/3-0049*temp1_input", + "/sys/bus/i2c/devices/3-004a*temp1_input", + "/sys/bus/i2c/devices/15-004c*temp1_input", + "/sys/bus/i2c/devices/15-004c*temp2_input", + "/sys/bus/i2c/devices/10-0058*psu_temp1_input", + "/sys/bus/i2c/devices/11-005b*psu_temp1_input", }; /* Static values */ @@ -128,24 +116,13 @@ onlp_thermali_init(void) int onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) { - int fd, len, nbytes = 10, temp_base=1, local_id; - char r_data[10] = {0}; - char fullpath[50] = {0}; + int local_id; VALIDATE(id); local_id = ONLP_OID_ID_GET(id); - DEBUG_PRINT("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id); - /* get fullpath */ - sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); - /* Set the onlp_oid_hdr_t and capabilities */ *info = linfo[local_id]; - OPEN_READ_FILE(fd, fullpath, r_data, nbytes, len); - info->mcelsius = atoi(r_data) / temp_base; - DEBUG_PRINT("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius); - - return ONLP_STATUS_OK; + return onlp_file_read_int(&info->mcelsius, devfiles__[local_id]); } -