From bef2b6bbb77e3c8ce76e19ee2b856a08ad32ee75 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 2 Jan 2017 15:23:17 +0000 Subject: [PATCH] Use the existing APIs to read the presence data. This also fixes an atoi buffer error when the input was not properly terminated. --- .../onlp/builds/src/module/src/sfpi.c | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c index ac02ac4e..10288992 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c @@ -32,31 +32,22 @@ #include #include "platform_lib.h" +#include #define MAX_SFP_PATH 64 static char sfp_node_path[MAX_SFP_PATH] = {0}; #define FRONT_PORT_TO_CPLD_MUX_INDEX(port) (port+2) -static int +static int as6812_32x_sfp_node_read_int(char *node_path, int *value, int data_len) { - int ret = 0; - char buf[8]; - *value = 0; - - ret = deviceNodeReadString(node_path, buf, sizeof(buf), data_len); - - if (ret == 0) { - *value = atoi(buf); - } - - return ret; + return onlp_file_read_int(value, node_path); } -static char* +static char* as6812_32x_sfp_get_port_path(int port, char *node_name) { - sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-0050/%s", + sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-0050/%s", FRONT_PORT_TO_CPLD_MUX_INDEX(port), node_name); @@ -71,7 +62,7 @@ as6812_32x_sfp_get_port_path(int port, char *node_name) int onlp_sfpi_init(void) { - /* Called at initialization time */ + /* Called at initialization time */ return ONLP_STATUS_OK; } @@ -83,7 +74,7 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) */ int p; AIM_BITMAP_CLR_ALL(bmap); - + for(p = 0; p < 32; p++) { AIM_BITMAP_SET(bmap, p); } @@ -106,7 +97,6 @@ onlp_sfpi_is_present(int port) AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } - return present; } @@ -119,7 +109,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) path = as6812_32x_sfp_get_port_path(0, "sfp_is_present_all"); fp = fopen(path, "r"); - + if(fp == NULL) { AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); return ONLP_STATUS_E_INTERNAL; @@ -172,7 +162,7 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) * Return OK if eeprom is read */ memset(data, 0, 256); - + if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) { AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; @@ -186,4 +176,3 @@ onlp_sfpi_denit(void) { return ONLP_STATUS_OK; } -