Browse Source

More simple structure of parse_local_cpus()

Serj Kalichev 3 years ago
parent
commit
993bc756c0
1 changed files with 20 additions and 25 deletions
  1. 20 25
      irq.c

+ 20 - 25
irq.c

@@ -131,53 +131,48 @@ static int parse_local_cpus(lub_list_t *irqs, const char *sysfs_path,
 	unsigned int num, lub_list_t *pxms)
 {
 	char path[PATH_MAX];
-	FILE *fd;
+	FILE *fd = NULL;
 	char *str = NULL;
 	size_t sz;
 	cpumask_t local_cpus;
 	irq_t *irq = NULL;
 	cpumask_t cpumask;
+	int ret = -1;
+
+	irq = irq_list_search(irqs, num);
+	if (!irq)
+		return ret;
 
 	cpus_init(local_cpus);
 	cpus_init(cpumask);
 
-	irq = irq_list_search(irqs, num);
-	if (!irq) {
-		cpus_free(local_cpus);
-		cpus_free(cpumask);
-		return -1;
-	}
-
 	/* Find proximity in config file. */
 	if (!pxm_search(pxms, sysfs_path, &cpumask)) {
 		cpus_copy(irq->local_cpus, cpumask);
-		cpus_free(local_cpus);
-		cpus_free(cpumask);
-		return 0;
+		ret = 0; /* success */
+		goto error;
 	}
 
 	snprintf(path, sizeof(path),
 		"%s/%s/local_cpus", SYSFS_PCI_PATH, sysfs_path);
 	path[sizeof(path) - 1] = '\0';
-	if (!(fd = fopen(path, "r"))){
-		cpus_free(local_cpus);
-		cpus_free(cpumask);
-		return -1;
-	}
-	if (getline(&str, &sz, fd) < 0) {
-		fclose(fd);
-		cpus_free(local_cpus);
-		cpus_free(cpumask);
-		return -1;
-	}
-	fclose(fd);
+	if (!(fd = fopen(path, "r")))
+		goto error;
+	if (getline(&str, &sz, fd) < 0)
+		goto error;
 	cpumask_parse_user(str, strlen(str), local_cpus);
 	cpus_and(irq->local_cpus, irq->local_cpus, local_cpus);
+	ret = 0; /* success */
+
+error:
+	if (fd)
+		fclose(fd);
+	if (str)
+		free(str);
 	cpus_free(local_cpus);
 	cpus_free(cpumask);
-	free(str);
 
-	return 0;
+	return ret;
 }
 
 static int parse_sysfs(lub_list_t *irqs, lub_list_t *pxms)