107 lines
3.3 KiB
Diff
107 lines
3.3 KiB
Diff
From 22a40e9d0dd59ee58ff06d2b6360007e046d608f Mon Sep 17 00:00:00 2001
|
|
From: liuchao173 <liuchao173@huawei.com>
|
|
Date: Thu, 7 Nov 2019 09:33:47 +0000
|
|
Subject: [PATCH 6/8] irqbalance: correct to use realloc() function
|
|
|
|
The man doc about realloc() say:
|
|
"
|
|
If realloc() fails the original block is left untouched; it is not
|
|
freed or move
|
|
"
|
|
|
|
So make the handling of realloc() function correctly.
|
|
|
|
In addition, there is another problem about parameter using in
|
|
sock_handle(), it should be use the address of @setup instead of @setup.
|
|
|
|
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
|
|
---
|
|
irqbalance.c | 33 +++++++++++++++++++++++----------
|
|
1 file changed, 23 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/irqbalance.c b/irqbalance.c
|
|
index c9378d0..cace4d8 100644
|
|
--- a/irqbalance.c
|
|
+++ b/irqbalance.c
|
|
@@ -321,14 +321,18 @@ gboolean scan(gpointer data)
|
|
void get_irq_data(struct irq_info *irq, void *data)
|
|
{
|
|
char **irqdata = (char **)data;
|
|
+ char *newptr = NULL;
|
|
+
|
|
if (!*irqdata)
|
|
- *irqdata = calloc(24 + 1 + 11 + 20 + 20 + 11, 1);
|
|
+ newptr = calloc(24 + 1 + 11 + 20 + 20 + 11, 1);
|
|
else
|
|
- *irqdata = realloc(*irqdata, strlen(*irqdata) + 24 + 1 + 11 + 20 + 20 + 11);
|
|
+ newptr = realloc(*irqdata, strlen(*irqdata) + 24 + 1 + 11 + 20 + 20 + 11);
|
|
|
|
- if (!*irqdata)
|
|
+ if (!newptr)
|
|
return;
|
|
|
|
+ *irqdata = newptr;
|
|
+
|
|
sprintf(*irqdata + strlen(*irqdata),
|
|
"IRQ %d LOAD %lu DIFF %lu CLASS %d ", irq->irq, irq->load,
|
|
(irq->irq_count - irq->last_irq_count), irq->class);
|
|
@@ -338,6 +342,7 @@ void get_object_stat(struct topo_obj *object, void *data)
|
|
{
|
|
char **stats = (char **)data;
|
|
char *irq_data = NULL;
|
|
+ char *newptr = NULL;
|
|
size_t irqdlen;
|
|
|
|
if (g_list_length(object->interrupts) > 0) {
|
|
@@ -355,13 +360,17 @@ void get_object_stat(struct topo_obj *object, void *data)
|
|
* This should be adjusted if the string in the sprintf is changed
|
|
*/
|
|
if (!*stats) {
|
|
- *stats = calloc(irqdlen + 31 + 11 + 20 + 11 + 1, 1);
|
|
+ newptr = calloc(irqdlen + 31 + 11 + 20 + 11 + 1, 1);
|
|
} else {
|
|
- *stats = realloc(*stats, strlen(*stats) + irqdlen + 31 + 11 + 20 + 11 + 1);
|
|
+ newptr = realloc(*stats, strlen(*stats) + irqdlen + 31 + 11 + 20 + 11 + 1);
|
|
}
|
|
|
|
- if (!*stats)
|
|
+ if (!newptr) {
|
|
+ free(irq_data);
|
|
return;
|
|
+ }
|
|
+
|
|
+ *stats = newptr;
|
|
|
|
sprintf(*stats + strlen(*stats), "TYPE %d NUMBER %d LOAD %lu SAVE_MODE %d %s",
|
|
object->obj_type, object->number, object->load,
|
|
@@ -475,19 +484,23 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
|
if (!strncmp(buff, "setup", strlen("setup"))) {
|
|
char banned[512];
|
|
char *setup = calloc(strlen("SLEEP ") + 11 + 1, 1);
|
|
+ char *newptr = NULL;
|
|
if (!setup)
|
|
goto out_close;
|
|
snprintf(setup, strlen("SLEEP ") + 11 + 1, "SLEEP %d ", sleep_interval);
|
|
if(g_list_length(cl_banned_irqs) > 0) {
|
|
- for_each_irq(cl_banned_irqs, get_irq_data, setup);
|
|
+ for_each_irq(cl_banned_irqs, get_irq_data, &setup);
|
|
}
|
|
cpumask_scnprintf(banned, 512, banned_cpus);
|
|
- setup = realloc(setup, strlen(setup) + strlen(banned) + 7 + 1);
|
|
- if (!setup)
|
|
- goto out_close;
|
|
+ newptr = realloc(setup, strlen(setup) + strlen(banned) + 7 + 1);
|
|
+ if (!newptr)
|
|
+ goto out_free_setup;
|
|
+
|
|
+ setup = newptr;
|
|
snprintf(setup + strlen(setup), strlen(banned) + 7 + 1,
|
|
"BANNED %s", banned);
|
|
send(sock, setup, strlen(setup), 0);
|
|
+out_free_setup:
|
|
free(setup);
|
|
}
|
|
|
|
--
|
|
2.19.1
|