mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-24 16:57:02 +00:00
Merge pull request #490 from toanju/as5712-format-overflow
x86-64-accton-as5712_54x fix -Werror=format-overflow
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
#define FAN_1_ON_PSU1 6
|
||||
#define FAN_1_ON_PSU2 7
|
||||
|
||||
#define PROJECT_NAME
|
||||
#define PROJECT_NAME
|
||||
|
||||
#define LEN_FILE_NAME 50
|
||||
|
||||
@@ -52,7 +52,7 @@ typedef struct last_path_S
|
||||
char status[LEN_FILE_NAME];
|
||||
char speed[LEN_FILE_NAME];
|
||||
char direction[LEN_FILE_NAME];
|
||||
char ctrl_speed[LEN_FILE_NAME];
|
||||
char ctrl_speed[LEN_FILE_NAME];
|
||||
char r_status[LEN_FILE_NAME];
|
||||
char r_speed[LEN_FILE_NAME];
|
||||
}last_path_T;
|
||||
@@ -75,10 +75,10 @@ static last_path_T last_path[] = /* must map with onlp_fan_id */
|
||||
MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_2_ON_MAIN_BOARD),
|
||||
MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_3_ON_MAIN_BOARD),
|
||||
MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_4_ON_MAIN_BOARD),
|
||||
MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_5_ON_MAIN_BOARD),
|
||||
MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_5_ON_MAIN_BOARD),
|
||||
|
||||
MAKE_FAN_LAST_PATH_ON_PSU(57-003c),
|
||||
MAKE_FAN_LAST_PATH_ON_PSU(58-003f),
|
||||
MAKE_FAN_LAST_PATH_ON_PSU(57-003c),
|
||||
MAKE_FAN_LAST_PATH_ON_PSU(58-003f),
|
||||
};
|
||||
|
||||
#define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \
|
||||
@@ -133,7 +133,7 @@ onlp_fan_info_t linfo[] = {
|
||||
printf("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \
|
||||
if (close(fd) == -1) \
|
||||
return ONLP_STATUS_E_INTERNAL
|
||||
|
||||
|
||||
|
||||
/* PSU relative marco */
|
||||
#define SET_PSU_TYPE_AC_F2B_FAN(info) \
|
||||
@@ -143,7 +143,7 @@ onlp_fan_info_t linfo[] = {
|
||||
#define SET_PSU_TYPE_AC_B2F_FAN(info) \
|
||||
info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F); \
|
||||
info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE
|
||||
|
||||
|
||||
#define SET_PSU_TYPE_UM400D_F2B_FAN(info) \
|
||||
info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B)
|
||||
|
||||
@@ -156,46 +156,46 @@ _onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info)
|
||||
{
|
||||
int fd, len, nbytes = 10;
|
||||
char r_data[10] = {0};
|
||||
char fullpath[65] = {0};
|
||||
|
||||
char fullpath[100] = {0};
|
||||
|
||||
/* get fan/fanr fault status (turn on when any one fails)
|
||||
*/
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].status);
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].status);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
if (atoi(r_data) > 0)
|
||||
info->status |= ONLP_FAN_STATUS_FAILED;
|
||||
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_status);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_status);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
if (atoi(r_data) > 0)
|
||||
info->status |= ONLP_FAN_STATUS_FAILED;
|
||||
|
||||
/* get fan/fanr direction (both : the same)
|
||||
/* get fan/fanr direction (both : the same)
|
||||
*/
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].direction);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].direction);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
|
||||
if (atoi(r_data) == 0) /*F2B*/
|
||||
info->status |= ONLP_FAN_STATUS_F2B;
|
||||
else
|
||||
else
|
||||
info->status |= ONLP_FAN_STATUS_B2F;
|
||||
|
||||
/* get fan/fanr speed (take the average of two speeds)
|
||||
*/
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].speed);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].speed);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
info->rpm = atoi(r_data);
|
||||
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_speed);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_speed);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
info->rpm = (info->rpm + atoi(r_data))/2;
|
||||
|
||||
/* get speed percentage from rpm */
|
||||
info->percentage = (info->rpm * 100)/16800;
|
||||
info->percentage = (info->rpm * 100)/16800;
|
||||
|
||||
/* check present */
|
||||
/* check present */
|
||||
if (info->rpm > 0)
|
||||
info->status |= ONLP_FAN_STATUS_PRESENT;
|
||||
info->status |= ONLP_FAN_STATUS_PRESENT;
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ _onlp_fani_info_get_fan_on_psu_ym2401(int pid, onlp_fan_info_t* info)
|
||||
if (psu_ym2401_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) {
|
||||
info->status |= (val > 0) ? 0 : ONLP_FAN_STATUS_FAILED;
|
||||
info->rpm = val;
|
||||
info->percentage = (info->rpm * 100) / 21600;
|
||||
info->percentage = (info->rpm * 100) / 21600;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
@@ -222,16 +222,16 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info)
|
||||
int psu_id;
|
||||
int fd, len, nbytes = 10;
|
||||
char r_data[10] = {0};
|
||||
char fullpath[50] = {0};
|
||||
char fullpath[100] = {0};
|
||||
psu_type_t psu_type;
|
||||
|
||||
/* get fan other cap status according to psu type
|
||||
|
||||
/* get fan other cap status according to psu type
|
||||
*/
|
||||
psu_id = (local_id-FAN_1_ON_PSU1) + 1;
|
||||
DEBUG_PRINT("[psu_id: %d]", psu_id);
|
||||
|
||||
DEBUG_PRINT("[psu_id: %d]", psu_id);
|
||||
|
||||
psu_type = get_psu_type(psu_id, NULL, 0); /* psu_id = 1 , present PSU1. pus_id =2 , present PSU2 */
|
||||
DEBUG_PRINT("[psu_type: %d]", psu_type);
|
||||
DEBUG_PRINT("[psu_type: %d]", psu_type);
|
||||
|
||||
switch (psu_type) {
|
||||
case PSU_TYPE_AC_COMPUWARE_F2B:
|
||||
@@ -250,26 +250,26 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info)
|
||||
break;
|
||||
default:
|
||||
if (LOCAL_DEBUG)
|
||||
printf("[Debug][%s][%d][psu_type=%d]\n", __FUNCTION__, __LINE__, psu_type);
|
||||
printf("[Debug][%s][%d][psu_type=%d]\n", __FUNCTION__, __LINE__, psu_type);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (psu_type == PSU_TYPE_AC_COMPUWARE_F2B ||
|
||||
psu_type == PSU_TYPE_AC_COMPUWARE_B2F )
|
||||
{
|
||||
/* get fan fault status
|
||||
/* get fan fault status
|
||||
*/
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].status);
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].status);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
if (atoi(r_data) > 0)
|
||||
info->status |= ONLP_FAN_STATUS_FAILED;
|
||||
|
||||
|
||||
/* get fan speed
|
||||
*/
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].speed);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
info->rpm = atoi(r_data);
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].speed);
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
info->rpm = atoi(r_data);
|
||||
|
||||
/* get speed percentage from rpm */
|
||||
info->percentage = (info->rpm * 100)/19328;
|
||||
@@ -279,7 +279,7 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info)
|
||||
{
|
||||
return _onlp_fani_info_get_fan_on_psu_ym2401(psu_id, info);
|
||||
}
|
||||
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
@@ -301,26 +301,26 @@ onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info)
|
||||
int local_id;
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
|
||||
local_id = ONLP_OID_ID_GET(id);
|
||||
|
||||
|
||||
*info = linfo[local_id];
|
||||
|
||||
|
||||
if (LOCAL_DEBUG)
|
||||
printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id);
|
||||
|
||||
|
||||
switch (local_id)
|
||||
{
|
||||
case FAN_1_ON_PSU1:
|
||||
case FAN_1_ON_PSU2:
|
||||
rc = _onlp_fani_info_get_fan_on_psu(local_id, info);
|
||||
rc = _onlp_fani_info_get_fan_on_psu(local_id, info);
|
||||
break;
|
||||
|
||||
default:
|
||||
rc =_onlp_fani_info_get_fan(local_id, info);
|
||||
rc =_onlp_fani_info_get_fan(local_id, info);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -349,20 +349,20 @@ onlp_fani_rpm_set(onlp_oid_t id, int rpm)
|
||||
*/
|
||||
int
|
||||
onlp_fani_percentage_set(onlp_oid_t id, int p)
|
||||
{
|
||||
{
|
||||
int fd, len, nbytes=10, local_id;
|
||||
char data[10] = {0};
|
||||
char fullpath[70] = {0};
|
||||
char data[10] = {0};
|
||||
char fullpath[100] = {0};
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
|
||||
local_id = ONLP_OID_ID_GET(id);
|
||||
|
||||
/* reject p=0 (p=0, stop fan) */
|
||||
if (p == 0){
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
}
|
||||
|
||||
|
||||
/* get fullpath */
|
||||
switch (local_id)
|
||||
{
|
||||
@@ -380,7 +380,7 @@ onlp_fani_percentage_set(onlp_oid_t id, int p)
|
||||
return psu_ym2401_pmbus_info_set(psu_id, "psu_fan1_duty_cycle_percentage", p);
|
||||
}
|
||||
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].ctrl_speed);
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].ctrl_speed);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -388,23 +388,23 @@ onlp_fani_percentage_set(onlp_oid_t id, int p)
|
||||
sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].ctrl_speed);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
sprintf(data, "%d", p);
|
||||
|
||||
if (LOCAL_DEBUG)
|
||||
printf("[Debug][%s][%d][openfile: %s][data=%s]\n", __FUNCTION__, __LINE__, fullpath, data);
|
||||
|
||||
|
||||
/* Create output file descriptor */
|
||||
fd = open(fullpath, O_WRONLY, 0644);
|
||||
if(fd == -1){
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
len = write (fd, data, (ssize_t) nbytes);
|
||||
if(len != nbytes){
|
||||
close(fd);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
close(fd);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return ONLP_STATUS_OK;
|
||||
|
||||
@@ -50,20 +50,20 @@ enum led_light_mode { /*must be the same with the definition @ kernel driver */
|
||||
LED_MODE_GREEN_BLINK,
|
||||
LED_MODE_AMBER_BLINK,
|
||||
LED_MODE_RED_BLINK,
|
||||
LED_MODE_AUTO,
|
||||
LED_MODE_AUTO,
|
||||
};
|
||||
|
||||
int led_light_map_mode[][2] =
|
||||
{
|
||||
{LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_MODE_GREEN, ONLP_LED_MODE_GREEN},
|
||||
{LED_MODE_AMBER, ONLP_LED_MODE_ORANGE},
|
||||
{LED_MODE_RED, ONLP_LED_MODE_RED},
|
||||
{LED_MODE_RED, ONLP_LED_MODE_RED},
|
||||
{LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING},
|
||||
{LED_MODE_AMBER_BLINK, ONLP_LED_MODE_ORANGE_BLINKING},
|
||||
{LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING},
|
||||
{LED_MODE_AUTO, ONLP_LED_MODE_AUTO},
|
||||
};
|
||||
{LED_MODE_AUTO, ONLP_LED_MODE_AUTO},
|
||||
};
|
||||
|
||||
|
||||
#define prefix_path "/sys/class/leds/accton_as5712_54x_led::"
|
||||
@@ -81,7 +81,7 @@ enum onlp_led_id
|
||||
LED_FAN2,
|
||||
LED_FAN3,
|
||||
LED_FAN4,
|
||||
LED_FAN5,
|
||||
LED_FAN5,
|
||||
};
|
||||
|
||||
static char last_path[][10] = /* must map with onlp_led_id */
|
||||
@@ -96,7 +96,7 @@ static char last_path[][10] = /* must map with onlp_led_id */
|
||||
"fan2",
|
||||
"fan3",
|
||||
"fan4",
|
||||
"fan5",
|
||||
"fan5",
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -160,7 +160,7 @@ static int conver_led_light_mode_to_onl(int led_ligth_mode)
|
||||
{
|
||||
if (led_ligth_mode == led_light_map_mode[i][0])
|
||||
{
|
||||
return led_light_map_mode[i][1];
|
||||
return led_light_map_mode[i][1];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -174,7 +174,7 @@ static int conver_led_light_mode_to_driver(int led_ligth_mode)
|
||||
{
|
||||
if (led_ligth_mode == led_light_map_mode[i][1])
|
||||
{
|
||||
return led_light_map_mode[i][0];
|
||||
return led_light_map_mode[i][0];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -200,40 +200,40 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
|
||||
|
||||
int fd, len, nbytes=1, local_id;
|
||||
char data[2] = {0};
|
||||
char fullpath[50] = {0};
|
||||
|
||||
char fullpath[100] = {0};
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
|
||||
local_id = ONLP_OID_ID_GET(id);
|
||||
|
||||
|
||||
/* get fullpath */
|
||||
if (strchr(last_path[local_id], '/') != NULL)
|
||||
{
|
||||
sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);
|
||||
sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
|
||||
sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
|
||||
}
|
||||
|
||||
/* Set the onlp_oid_hdr_t and capabilities */
|
||||
|
||||
/* Set the onlp_oid_hdr_t and capabilities */
|
||||
*info = linfo[ONLP_OID_ID_GET(id)];
|
||||
|
||||
/* Set current mode */
|
||||
if ((fd = open(fullpath, O_RDONLY)) == -1)
|
||||
{
|
||||
{
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
if ((len = read(fd, data, nbytes)) <= 0)
|
||||
{
|
||||
close(fd);
|
||||
close(fd);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
/* If the read byte count is less, the format is different and calc will be wrong*/
|
||||
if (close(fd) == -1)
|
||||
{
|
||||
{
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -278,37 +278,37 @@ int
|
||||
onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode)
|
||||
{
|
||||
int fd, len, driver_mode, nbytes=1, local_id;
|
||||
char data[2] = {0};
|
||||
char fullpath[50] = {0};
|
||||
char data[2] = {0};
|
||||
char fullpath[100] = {0};
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
|
||||
local_id = ONLP_OID_ID_GET(id);
|
||||
|
||||
|
||||
/* get fullpath */
|
||||
if (strchr(last_path[local_id], '/') != NULL)
|
||||
{
|
||||
sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);
|
||||
sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
|
||||
sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
|
||||
}
|
||||
|
||||
|
||||
driver_mode = conver_led_light_mode_to_driver(mode);
|
||||
sprintf(data, "%d", driver_mode);
|
||||
|
||||
|
||||
/* Create output file descriptor */
|
||||
fd = open(fullpath, O_WRONLY, 0644);
|
||||
if(fd == -1){
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
len = write (fd, data, (ssize_t) nbytes);
|
||||
if(len != nbytes){
|
||||
close(fd);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
close(fd);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return ONLP_STATUS_OK;
|
||||
|
||||
Reference in New Issue
Block a user