irqbalance/bugfix-make-the-return-value-of-getline-handled-correct.patch
2019-12-13 15:29:40 +08:00

119 lines
3.3 KiB
Diff

From 74970054568728d11dbbb160e0c5cacdfeb07ff3 Mon Sep 17 00:00:00 2001
From: liuchao <liuchao173@huawei.com>
Date: Fri, 11 Oct 2019 07:49:55 +0000
Subject: [PATCH] irqbalance: make the return value of getline() handled correct
getline() will return -1 when fail, so make the return value handle correct.
---
activate.c | 2 +-
cputree.c | 6 +++---
procinterrupts.c | 12 ++++++------
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/activate.c b/activate.c
index ad60fde..87336f4 100644
--- a/activate.c
+++ b/activate.c
@@ -47,7 +47,7 @@ static int check_affinity(struct irq_info *info, cpumask_t applied_mask)
file = fopen(buf, "r");
if (!file)
return 1;
- if (getline(&line, &size, file)==0) {
+ if (getline(&line, &size, file)<=0) {
free(line);
fclose(file);
return 1;
diff --git a/cputree.c b/cputree.c
index 0dbb5c8..51ef357 100644
--- a/cputree.c
+++ b/cputree.c
@@ -324,7 +324,7 @@ static void do_one_cpu(char *path)
if (file) {
char *line = NULL;
size_t size = 0;
- if (getline(&line, &size, file))
+ if (getline(&line, &size, file) > 0)
cpumask_parse_user(line, strlen(line), package_mask);
fclose(file);
free(line);
@@ -336,7 +336,7 @@ static void do_one_cpu(char *path)
if (file) {
char *line = NULL;
size_t size = 0;
- if (getline(&line, &size, file))
+ if (getline(&line, &size, file) > 0)
packageid = strtoul(line, NULL, 10);
fclose(file);
free(line);
@@ -369,7 +369,7 @@ static void do_one_cpu(char *path)
if (file) {
char *line = NULL;
size_t size = 0;
- if (getline(&line, &size, file))
+ if (getline(&line, &size, file) > 0)
cpumask_parse_user(line, strlen(line), cache_mask);
fclose(file);
free(line);
diff --git a/procinterrupts.c b/procinterrupts.c
index 18b3ceb..c32c1b2 100644
--- a/procinterrupts.c
+++ b/procinterrupts.c
@@ -262,7 +262,7 @@ GList* collect_full_irq_list()
return NULL;
/* first line is the header we don't need; nuke it */
- if (getline(&line, &size, file)==0) {
+ if (getline(&line, &size, file)<=0) {
free(line);
fclose(file);
return NULL;
@@ -274,7 +274,7 @@ GList* collect_full_irq_list()
char *c;
char *savedline = NULL;
- if (getline(&line, &size, file)==0)
+ if (getline(&line, &size, file)<=0)
break;
/* lines with letters in front are special, like NMI count. Ignore */
@@ -349,7 +349,7 @@ void parse_proc_interrupts(void)
return;
/* first line is the header we don't need; nuke it */
- if (getline(&line, &size, file)==0) {
+ if (getline(&line, &size, file)<=0) {
free(line);
fclose(file);
return;
@@ -365,7 +365,7 @@ void parse_proc_interrupts(void)
char savedline[1024];
char dirname[PATH_MAX] = {'\0'};
- if (getline(&line, &size, file)==0)
+ if (getline(&line, &size, file)<=0)
break;
if (!proc_int_has_msi)
@@ -579,7 +579,7 @@ void parse_proc_stat(void)
}
/* first line is the header we don't need; nuke it */
- if (getline(&line, &size, file)==0) {
+ if (getline(&line, &size, file)<=0) {
free(line);
log(TO_ALL, LOG_WARNING, "WARNING read /proc/stat. balancing is broken\n");
fclose(file);
@@ -588,7 +588,7 @@ void parse_proc_stat(void)
cpucount = 0;
while (!feof(file)) {
- if (getline(&line, &size, file)==0)
+ if (getline(&line, &size, file)<=0)
break;
if (!strstr(line, "cpu"))
--
2.19.1