diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2018-04-04 06:40:07 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2018-04-06 06:19:50 -0400 |
| commit | 0211e12dd0a5385ecffd3557bc570dbad7fcf245 (patch) | |
| tree | 7565018404d1075b968f69ee4e90b2bf5b9cf981 | |
| parent | 83fbdf1c0595470d98ee99a6474099aee870640f (diff) | |
genirq/affinity: Don't return with empty affinity masks on error
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: 9a0ef98e186d ("genirq/affinity: Assign vectors to all present CPUs")
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ming Lei <ming.lei@redhat.com>
| -rw-r--r-- | kernel/irq/affinity.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index a37a3b4b6342..e0665549af59 100644 --- a/kernel/irq/affinity.c +++ b/kernel/irq/affinity.c | |||
| @@ -108,7 +108,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) | |||
| 108 | int affv = nvecs - affd->pre_vectors - affd->post_vectors; | 108 | int affv = nvecs - affd->pre_vectors - affd->post_vectors; |
| 109 | int last_affv = affv + affd->pre_vectors; | 109 | int last_affv = affv + affd->pre_vectors; |
| 110 | nodemask_t nodemsk = NODE_MASK_NONE; | 110 | nodemask_t nodemsk = NODE_MASK_NONE; |
| 111 | struct cpumask *masks; | 111 | struct cpumask *masks = NULL; |
| 112 | cpumask_var_t nmsk, *node_to_possible_cpumask; | 112 | cpumask_var_t nmsk, *node_to_possible_cpumask; |
| 113 | 113 | ||
| 114 | /* | 114 | /* |
| @@ -121,13 +121,13 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) | |||
| 121 | if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) | 121 | if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) |
| 122 | return NULL; | 122 | return NULL; |
| 123 | 123 | ||
| 124 | masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL); | ||
| 125 | if (!masks) | ||
| 126 | goto out; | ||
| 127 | |||
| 128 | node_to_possible_cpumask = alloc_node_to_possible_cpumask(); | 124 | node_to_possible_cpumask = alloc_node_to_possible_cpumask(); |
| 129 | if (!node_to_possible_cpumask) | 125 | 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; | ||
| 131 | 131 | ||
| 132 | /* Fill out vectors at the beginning that don't need affinity */ | 132 | /* Fill out vectors at the beginning that don't need affinity */ |
| 133 | for (curvec = 0; curvec < affd->pre_vectors; curvec++) | 133 | for (curvec = 0; curvec < affd->pre_vectors; curvec++) |
| @@ -192,8 +192,9 @@ done: | |||
| 192 | /* Fill out vectors at the end that don't need affinity */ | 192 | /* Fill out vectors at the end that don't need affinity */ |
| 193 | for (; curvec < nvecs; curvec++) | 193 | for (; curvec < nvecs; curvec++) |
| 194 | cpumask_copy(masks + curvec, irq_default_affinity); | 194 | cpumask_copy(masks + curvec, irq_default_affinity); |
| 195 | outnodemsk: | ||
| 195 | free_node_to_possible_cpumask(node_to_possible_cpumask); | 196 | free_node_to_possible_cpumask(node_to_possible_cpumask); |
| 196 | out: | 197 | outcpumsk: |
| 197 | free_cpumask_var(nmsk); | 198 | free_cpumask_var(nmsk); |
| 198 | return masks; | 199 | return masks; |
| 199 | } | 200 | } |
