Commit 76369ed5 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Greg Kroah-Hartman

genirq/affinity: Don't return with empty affinity masks on error

commit 0211e12d upstream.

When the allocation of node_to_possible_cpumask fails, then
irq_create_affinity_masks() returns with a pointer to the empty affinity
masks array, which will cause malfunction.

Reorder the allocations so the masks array allocation comes last and every
failure path returns NULL.

Fixes: 9a0ef98e ("genirq/affinity: Assign vectors to all present CPUs")
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Mihai Carabas <mihai.carabas@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0840feb3
...@@ -108,7 +108,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) ...@@ -108,7 +108,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
int affv = nvecs - affd->pre_vectors - affd->post_vectors; int affv = nvecs - affd->pre_vectors - affd->post_vectors;
int last_affv = affv + affd->pre_vectors; int last_affv = affv + affd->pre_vectors;
nodemask_t nodemsk = NODE_MASK_NONE; nodemask_t nodemsk = NODE_MASK_NONE;
struct cpumask *masks; struct cpumask *masks = NULL;
cpumask_var_t nmsk, *node_to_possible_cpumask; cpumask_var_t nmsk, *node_to_possible_cpumask;
/* /*
...@@ -121,13 +121,13 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) ...@@ -121,13 +121,13 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
return NULL; return NULL;
masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL);
if (!masks)
goto out;
node_to_possible_cpumask = alloc_node_to_possible_cpumask(); node_to_possible_cpumask = alloc_node_to_possible_cpumask();
if (!node_to_possible_cpumask) if (!node_to_possible_cpumask)
goto out; goto outcpumsk;
masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL);
if (!masks)
goto outnodemsk;
/* Fill out vectors at the beginning that don't need affinity */ /* Fill out vectors at the beginning that don't need affinity */
for (curvec = 0; curvec < affd->pre_vectors; curvec++) for (curvec = 0; curvec < affd->pre_vectors; curvec++)
...@@ -192,8 +192,9 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) ...@@ -192,8 +192,9 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
/* Fill out vectors at the end that don't need affinity */ /* Fill out vectors at the end that don't need affinity */
for (; curvec < nvecs; curvec++) for (; curvec < nvecs; curvec++)
cpumask_copy(masks + curvec, irq_default_affinity); cpumask_copy(masks + curvec, irq_default_affinity);
outnodemsk:
free_node_to_possible_cpumask(node_to_possible_cpumask); free_node_to_possible_cpumask(node_to_possible_cpumask);
out: outcpumsk:
free_cpumask_var(nmsk); free_cpumask_var(nmsk);
return masks; return masks;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment