From 7ffe84fdce94e03c7d8c7f654cbb112c76dea20b Mon Sep 17 00:00:00 2001 From: wanghaibin Date: Sat, 19 Aug 2017 01:00:19 +0800 Subject: [PATCH 1/3] irqbalance: Fix the compile warning. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fix the compile warningis like as folow: ui/irqbalance-ui.c:147:20: warning: ‘ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized] new_irq->class = strtol(strtok_r(NULL, " ", &ptr), NULL, 10); Signed-off-by: wanghaibin --- ui/irqbalance-ui.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c index 9215877..3fc46af 100644 --- a/ui/irqbalance-ui.c +++ b/ui/irqbalance-ui.c @@ -125,6 +125,8 @@ void parse_setup(char *setup_data) char *copy; if((setup_data == NULL) || (strlen(setup_data) == 0)) return; copy = strdup(setup_data); + if (!copy) + return; setup.banned_irqs = NULL; setup.banned_cpus = NULL; @@ -243,6 +245,9 @@ void parse_into_tree(char *data) return; copy = strdup(data); + if (!copy) + return; + token = strtok_r(copy, " ", &ptr); while(token != NULL) { /* Parse node data */ From 96deefcc51a0741d1a5bbfd78da3aedb15b7c412 Mon Sep 17 00:00:00 2001 From: wanghaibin Date: Fri, 18 Aug 2017 19:38:56 +0800 Subject: [PATCH 2/3] irqbalance: optimize the check platform device func. Abstract a platform device irq info struct include dir name, irq type and irq class. This can simplify the compare code logic, to avoid unnecessary error just like the spell error as follow: else if (!strncmp(ent->d_name, "usb", strlen("net"))) Signed-off-by: wanghaibin --- procinterrupts.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/procinterrupts.c b/procinterrupts.c index c5c034c..57051c8 100644 --- a/procinterrupts.c +++ b/procinterrupts.c @@ -57,7 +57,17 @@ static int check_platform_device(char *name, struct irq_info *info) DIR *dirfd; char path[512]; struct dirent *ent; - int rc = -ENOENT; + int rc = -ENOENT, i; + static struct pdev_irq_info{ + char *d_name; + int type; + int class; + } pdev_irq_info[] = { + {"ata", IRQ_TYPE_LEGACY, IRQ_SCSI}, + {"net", IRQ_TYPE_LEGACY, IRQ_ETH}, + {"usb", IRQ_TYPE_LEGACY, IRQ_OTHER}, + {NULL}, + }; memset(path, 0, 512); @@ -74,21 +84,13 @@ static int check_platform_device(char *name, struct irq_info *info) while ((ent = readdir(dirfd)) != NULL) { log(TO_ALL, LOG_DEBUG, "Checking entry %s\n", ent->d_name); - if (!strncmp(ent->d_name, "ata", strlen("ata"))) { - info->type = IRQ_TYPE_LEGACY; - info->class = IRQ_SCSI; - rc = 0; - goto out; - } else if (!strncmp(ent->d_name, "net", strlen("net"))) { - info->type = IRQ_TYPE_LEGACY; - info->class = IRQ_ETH; - rc = 0; - goto out; - } else if (!strncmp(ent->d_name, "usb", strlen("net"))) { - info->type = IRQ_TYPE_LEGACY; - info->class = IRQ_OTHER; - rc = 0; - goto out; + for (i = 0; pdev_irq_info[i].d_name != NULL; i++) { + if (!strncmp(ent->d_name, pdev_irq_info[i].d_name, strlen(pdev_irq_info[i].d_name))) { + info->type = pdev_irq_info[i].type; + info->class = pdev_irq_info[i].class; + rc = 0; + goto out; + } } } From 989aefcef4b04c7db87c153a85294adebfe4512a Mon Sep 17 00:00:00 2001 From: wanghaibin-mouse <31118637+wanghaibin-mouse@users.noreply.github.com> Date: Tue, 29 Aug 2017 17:10:20 +0800 Subject: [PATCH 3/3] Update procinterrupts.c --- procinterrupts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/procinterrupts.c b/procinterrupts.c index 57051c8..eb84a1c 100644 --- a/procinterrupts.c +++ b/procinterrupts.c @@ -58,7 +58,7 @@ static int check_platform_device(char *name, struct irq_info *info) char path[512]; struct dirent *ent; int rc = -ENOENT, i; - static struct pdev_irq_info{ + static struct pdev_irq_info { char *d_name; int type; int class;