From 4c6a95756390c4de586ec382fac4d55e9c47a7b4 Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 26 Jan 2017 15:08:49 +0800 Subject: [PATCH] [LY6,LY9] 1. Use search syntax to find devices files 2. Use aim_strlcpy to make sure the model and serial number strings are NULL terminated (strncpy does not NULL terminate) --- .../module/src/psui.c | 29 +++++++++++-------- .../module/src/psui.c | 29 +++++++++++-------- 2 files changed, 34 insertions(+), 24 deletions(-) mode change 100644 => 100755 packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c old mode 100644 new mode 100755 index 930e9df7..76272a57 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c @@ -15,6 +15,7 @@ #include #include "x86_64_quanta_ly6_rangeley_int.h" #include "x86_64_quanta_ly6_rangeley_log.h" +#include struct psu_info_s psu_info[] = { {}, /* Not used */ @@ -76,7 +77,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) return 0; } - if(onlp_file_read_int(&info->mvin, "%s/in1_input", dir) == 0 && info->mvin >= 0) { + if(onlp_file_read_int(&info->mvin, "%s*in1_input", dir) == 0 && info->mvin >= 0) { info->caps |= ONLP_PSU_CAPS_VIN; } @@ -85,37 +86,41 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) memset(buffer, 0, sizeof(buffer)); rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); - if(rv >= 0) - strncpy(info->model, (char *) (buffer+1), (buffer[0] + 1)); - else + if(rv >= 0){ + aim_strlcpy(info->model, (char *) (buffer+1), (buffer[0] + 1)); + } + else{ strcpy(info->model, "Missing"); + } memset(buffer, 0, sizeof(buffer)); rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); - if(rv >= 0) - strncpy(info->serial, (char *) (buffer+1), (buffer[0] + 1)); - else + if(rv >= 0){ + aim_strlcpy(info->serial, (char *) (buffer+1), (buffer[0] + 1)); + } + else{ strcpy(info->serial, "Missing"); + } info->caps |= ONLP_PSU_CAPS_AC; - if(onlp_file_read_int(&info->miin, "%s/curr1_input", dir) == 0 && info->miin >= 0) { + if(onlp_file_read_int(&info->miin, "%s*curr1_input", dir) == 0 && info->miin >= 0) { info->caps |= ONLP_PSU_CAPS_IIN; } - if(onlp_file_read_int(&info->miout, "%s/curr2_input", dir) == 0 && info->miout >= 0) { + if(onlp_file_read_int(&info->miout, "%s*curr2_input", dir) == 0 && info->miout >= 0) { info->caps |= ONLP_PSU_CAPS_IOUT; } - if(onlp_file_read_int(&info->mvout, "%s/in2_input", dir) == 0 && info->mvout >= 0) { + if(onlp_file_read_int(&info->mvout, "%s*in2_input", dir) == 0 && info->mvout >= 0) { info->caps |= ONLP_PSU_CAPS_VOUT; /* Empirical */ info->mvout /= 500; } - if(onlp_file_read_int(&info->mpin, "%s/power1_input", dir) == 0 && info->mpin >= 0) { + if(onlp_file_read_int(&info->mpin, "%s*power1_input", dir) == 0 && info->mpin >= 0) { info->caps |= ONLP_PSU_CAPS_PIN; /* The pmbus driver reports power in micro-units */ info->mpin /= 1000; } - if(onlp_file_read_int(&info->mpout, "%s/power2_input", dir) == 0 && info->mpout >= 0) { + if(onlp_file_read_int(&info->mpout, "%s*power2_input", dir) == 0 && info->mpout >= 0) { info->caps |= ONLP_PSU_CAPS_POUT; /* the pmbus driver reports power in micro-units */ info->mpout /= 1000; diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c index 512c3153..1810fa46 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c @@ -15,6 +15,7 @@ #include #include "x86_64_quanta_ly9_rangeley_int.h" #include "x86_64_quanta_ly9_rangeley_log.h" +#include struct psu_info_s psu_info[] = { {}, /* Not used */ @@ -76,7 +77,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) return 0; } - if(onlp_file_read_int(&info->mvin, "%s/in1_input", dir) == 0 && info->mvin >= 0) { + if(onlp_file_read_int(&info->mvin, "%s*in1_input", dir) == 0 && info->mvin >= 0) { info->caps |= ONLP_PSU_CAPS_VIN; } @@ -86,36 +87,40 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) memset(buffer, 0, sizeof(buffer)); rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); buffer[buffer[0] + 1] = 0x00; - if(rv >= 0) - strncpy(info->model, (char *) (buffer+1), (buffer[0] + 1)); - else + if(rv >= 0){ + aim_strlcpy(info->model, (char *) (buffer+1), (buffer[0] + 1)); + } + else{ strcpy(info->model, "Missing"); + } memset(buffer, 0, sizeof(buffer)); rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); buffer[buffer[0] + 1] = 0x00; - if(rv >= 0) - strncpy(info->serial, (char *) (buffer+1), (buffer[0] + 1)); - else + if(rv >= 0){ + aim_strlcpy(info->serial, (char *) (buffer+1), (buffer[0] + 1)); + } + else{ strcpy(info->serial, "Missing"); + } info->caps |= ONLP_PSU_CAPS_AC; - if(onlp_file_read_int(&info->miin, "%s/curr1_input", dir) == 0 && info->miin >= 0) { + if(onlp_file_read_int(&info->miin, "%s*curr1_input", dir) == 0 && info->miin >= 0) { info->caps |= ONLP_PSU_CAPS_IIN; } - if(onlp_file_read_int(&info->miout, "%s/curr2_input", dir) == 0 && info->miout >= 0) { + if(onlp_file_read_int(&info->miout, "%s*/curr2_input", dir) == 0 && info->miout >= 0) { info->caps |= ONLP_PSU_CAPS_IOUT; } - if(onlp_file_read_int(&info->mvout, "%s/in2_input", dir) == 0 && info->mvout >= 0) { + if(onlp_file_read_int(&info->mvout, "%s*in2_input", dir) == 0 && info->mvout >= 0) { info->caps |= ONLP_PSU_CAPS_VOUT; } - if(onlp_file_read_int(&info->mpin, "%s/power1_input", dir) == 0 && info->mpin >= 0) { + if(onlp_file_read_int(&info->mpin, "%s*power1_input", dir) == 0 && info->mpin >= 0) { info->caps |= ONLP_PSU_CAPS_PIN; /* The pmbus driver reports power in micro-units */ info->mpin /= 1000; } - if(onlp_file_read_int(&info->mpout, "%s/power2_input", dir) == 0 && info->mpout >= 0) { + if(onlp_file_read_int(&info->mpout, "%s*power2_input", dir) == 0 && info->mpout >= 0) { info->caps |= ONLP_PSU_CAPS_POUT; /* the pmbus driver reports power in micro-units */ info->mpout /= 1000;