Skip to content

Commit 76369ed

Browse files
KAGA-KOKOgregkh
authored andcommitted
genirq/affinity: Don't return with empty affinity masks on error
commit 0211e12 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: 9a0ef98 ("genirq/affinity: Assign vectors to all present CPUs") Signed-off-by: Thomas Gleixner <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Ming Lei <[email protected]> Cc: Mihai Carabas <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0840feb commit 76369ed

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

kernel/irq/affinity.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
108108
int affv = nvecs - affd->pre_vectors - affd->post_vectors;
109109
int last_affv = affv + affd->pre_vectors;
110110
nodemask_t nodemsk = NODE_MASK_NONE;
111-
struct cpumask *masks;
111+
struct cpumask *masks = NULL;
112112
cpumask_var_t nmsk, *node_to_possible_cpumask;
113113

114114
/*
@@ -121,13 +121,13 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
121121
if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
122122
return NULL;
123123

124-
masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL);
125-
if (!masks)
126-
goto out;
127-
128124
node_to_possible_cpumask = alloc_node_to_possible_cpumask();
129125
if (!node_to_possible_cpumask)
130-
goto out;
126+
goto outcpumsk;
127+
128+
masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL);
129+
if (!masks)
130+
goto outnodemsk;
131131

132132
/* Fill out vectors at the beginning that don't need affinity */
133133
for (curvec = 0; curvec < affd->pre_vectors; curvec++)
@@ -192,8 +192,9 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
192192
/* Fill out vectors at the end that don't need affinity */
193193
for (; curvec < nvecs; curvec++)
194194
cpumask_copy(masks + curvec, irq_default_affinity);
195+
outnodemsk:
195196
free_node_to_possible_cpumask(node_to_possible_cpumask);
196-
out:
197+
outcpumsk:
197198
free_cpumask_var(nmsk);
198199
return masks;
199200
}

0 commit comments

Comments
 (0)