Fix return value type issue and some cleanup.
Xiaofei Tan (3): rasdaemon: fix return value type issue of read/write function from unistd.h rasdaemon: fix issue of signed and unsigned integer comparison rasdaemon: remove redundant header file and do some cleaup
non-standard-hisi_hip08.c | 2 +- non-standard-hisilicon.c | 4 ++-- ras-diskerror-handler.c | 2 +- ras-events.c | 45 ++++++++++++++++++++++++------------ ras-memory-failure-handler.c | 7 +++--- 5 files changed, 37 insertions(+), 23 deletions(-)
The return value type of read/write function from unistd.h is ssize_t. It's signed normaly, and return -1 on error. Fix incorrect use in the function read_ras_event_all_cpus().
BTW, make setting buffer_percent as a separate function.
Fixes: 94750bcf9309 ("rasdaemon: Fix poll() on per_cpu trace_pipe_raw blocks indefinitely") Signed-off-by: Xiaofei Tan tanxiaofei@huawei.com --- ras-events.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/ras-events.c b/ras-events.c index 2662467..d041828 100644 --- a/ras-events.c +++ b/ras-events.c @@ -368,10 +368,37 @@ static int get_num_cpus(struct ras_events *ras) #endif }
+static int set_buffer_percent(struct ras_events *ras, int percent) +{ + char buf[16]; + ssize_t size; + int res = 0; + int fd; + + fd = open_trace(ras, "buffer_percent", O_WRONLY); + if (fd >= 0) { + /* For the backward compatibility to the old kernels, do not return + * if fail to set the buffer_percent. + */ + snprintf(buf, sizeof(buf), "%d", percent); + size = write(fd, buf, strlen(buf)); + if (size <= 0) { + log(TERM, LOG_WARNING, "can't write to buffer_percent\n"); + res = -1; + } + close(fd); + } else { + log(TERM, LOG_WARNING, "Can't open buffer_percent\n"); + res = -1; + } + + return res; +} + static int read_ras_event_all_cpus(struct pthread_data *pdata, unsigned n_cpus) { - unsigned size; + ssize_t size; unsigned long long time_stamp; void *data; int ready, i, count_nready; @@ -383,8 +410,6 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata, int warnonce[n_cpus]; char pipe_raw[PATH_MAX]; int legacy_kernel = 0; - int fd; - char buf[16]; #if 0 int need_sleep = 0; #endif @@ -411,18 +436,8 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata, * Set buffer_percent to 0 so that poll() will return immediately * when the trace data is available in the ras per_cpu trace pipe_raw */ - fd = open_trace(pdata[0].ras, "buffer_percent", O_WRONLY); - if (fd >= 0) { - /* For the backward compatibility to the old kernels, do not return - * if fail to set the buffer_percent. - */ - snprintf(buf, sizeof(buf), "0"); - size = write(fd, buf, strlen(buf)); - if (size <= 0) - log(TERM, LOG_WARNING, "can't write to buffer_percent\n"); - close(fd); - } else - log(TERM, LOG_WARNING, "Can't open buffer_percent\n"); + if (set_buffer_percent(pdata[0].ras, 0)) + log(TERM, LOG_WARNING, "Set buffer_percent failed\n");
for (i = 0; i < (n_cpus + 1); i++) fds[i].fd = -1;
The return value of ARRAY_SIZE() is unsigned integer. It isn't right to compare it with a signed integer. This patch fix them.
Signed-off-by: Xiaofei Tan tanxiaofei@huawei.com --- non-standard-hisi_hip08.c | 2 +- non-standard-hisilicon.c | 4 ++-- ras-diskerror-handler.c | 2 +- ras-memory-failure-handler.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/non-standard-hisi_hip08.c b/non-standard-hisi_hip08.c index 4ef47ea..61f12eb 100644 --- a/non-standard-hisi_hip08.c +++ b/non-standard-hisi_hip08.c @@ -1029,7 +1029,7 @@ static struct ras_ns_ev_decoder hip08_ns_ev_decoder[] = {
static void __attribute__((constructor)) hip08_init(void) { - int i; + unsigned int i;
for (i = 0; i < ARRAY_SIZE(hip08_ns_ev_decoder); i++) register_ns_ev_decoder(&hip08_ns_ev_decoder[i]); diff --git a/non-standard-hisilicon.c b/non-standard-hisilicon.c index 2b00ed6..9873919 100644 --- a/non-standard-hisilicon.c +++ b/non-standard-hisilicon.c @@ -366,7 +366,7 @@ static int decode_hisi_common_section(struct ras_events *ras, trace_seq_printf(s, "%s\n", hevent.error_msg);
if (err->val_bits & BIT(HISI_COMMON_VALID_REG_ARRAY_SIZE) && err->reg_array_size > 0) { - int i; + unsigned int i;
trace_seq_printf(s, "Register Dump:\n"); for (i = 0; i < err->reg_array_size / sizeof(uint32_t); i++) { @@ -398,7 +398,7 @@ static struct ras_ns_ev_decoder hisi_section_ns_ev_decoder[] = {
static void __attribute__((constructor)) hisi_ns_init(void) { - int i; + unsigned int i;
for (i = 0; i < ARRAY_SIZE(hisi_section_ns_ev_decoder); i++) register_ns_ev_decoder(&hisi_section_ns_ev_decoder[i]); diff --git a/ras-diskerror-handler.c b/ras-diskerror-handler.c index 38d0a36..638cb4d 100644 --- a/ras-diskerror-handler.c +++ b/ras-diskerror-handler.c @@ -52,7 +52,7 @@ static const struct {
static const char *get_blk_error(int err) { - int i; + unsigned int i;
for (i = 0; i < ARRAY_SIZE(blk_errors); i++) if (blk_errors[i].error == err) diff --git a/ras-memory-failure-handler.c b/ras-memory-failure-handler.c index 72c65de..85a8633 100644 --- a/ras-memory-failure-handler.c +++ b/ras-memory-failure-handler.c @@ -99,7 +99,7 @@ static const struct {
static const char *get_page_type(int page_type) { - int i; + unsigned int i;
for (i = 0; i < ARRAY_SIZE(mf_page_type); i++) if (mf_page_type[i].type == page_type) @@ -110,7 +110,7 @@ static const char *get_page_type(int page_type)
static const char *get_action_result(int result) { - int i; + unsigned int i;
for (i = 0; i < ARRAY_SIZE(mf_action_result); i++) if (mf_action_result[i].result == result)
1.Remove redundant header file and adjust the header files sequence. 2.Use right character format for printf.
Signed-off-by: Xiaofei Tan tanxiaofei@huawei.com --- ras-memory-failure-handler.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/ras-memory-failure-handler.c b/ras-memory-failure-handler.c index 85a8633..c74541f 100644 --- a/ras-memory-failure-handler.c +++ b/ras-memory-failure-handler.c @@ -15,11 +15,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <traceevent/kbuffer.h> -#include "ras-memory-failure-handler.h" #include "ras-record.h" #include "ras-logger.h" #include "ras-report.h" +#include "ras-memory-failure-handler.h"
/* Memory failure - various types of pages */ enum mf_action_page_type {