Skip to content

Commit 59482a1

Browse files
ssanchez11dledford
authored andcommitted
IB/hfi1: Fix memory leak in exception path in get_irq_affinity()
When IRQ affinity is set and the interrupt type is unknown, a cpu mask allocated within the function is never freed. Fix this memory leak by allocating memory within the scope where it is used. Reviewed-by: Mike Marciniszyn <[email protected]> Reviewed-by: Michael J. Ruhl <[email protected]> Signed-off-by: Sebastian Sanchez <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent e9777ad commit 59482a1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/infiniband/hw/hfi1/affinity.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ static void hfi1_cleanup_sdma_notifier(struct hfi1_msix_entry *msix)
412412
static int get_irq_affinity(struct hfi1_devdata *dd,
413413
struct hfi1_msix_entry *msix)
414414
{
415-
int ret;
416415
cpumask_var_t diff;
417416
struct hfi1_affinity_node *entry;
418417
struct cpu_mask_set *set = NULL;
@@ -424,10 +423,6 @@ static int get_irq_affinity(struct hfi1_devdata *dd,
424423
extra[0] = '\0';
425424
cpumask_clear(&msix->mask);
426425

427-
ret = zalloc_cpumask_var(&diff, GFP_KERNEL);
428-
if (!ret)
429-
return -ENOMEM;
430-
431426
entry = node_affinity_lookup(dd->node);
432427

433428
switch (msix->type) {
@@ -458,6 +453,9 @@ static int get_irq_affinity(struct hfi1_devdata *dd,
458453
* finds its CPU here.
459454
*/
460455
if (cpu == -1 && set) {
456+
if (!zalloc_cpumask_var(&diff, GFP_KERNEL))
457+
return -ENOMEM;
458+
461459
if (cpumask_equal(&set->mask, &set->used)) {
462460
/*
463461
* We've used up all the CPUs, bump up the generation
@@ -469,6 +467,8 @@ static int get_irq_affinity(struct hfi1_devdata *dd,
469467
cpumask_andnot(diff, &set->mask, &set->used);
470468
cpu = cpumask_first(diff);
471469
cpumask_set_cpu(cpu, &set->used);
470+
471+
free_cpumask_var(diff);
472472
}
473473

474474
cpumask_set_cpu(cpu, &msix->mask);
@@ -482,7 +482,6 @@ static int get_irq_affinity(struct hfi1_devdata *dd,
482482
hfi1_setup_sdma_notifier(msix);
483483
}
484484

485-
free_cpumask_var(diff);
486485
return 0;
487486
}
488487

0 commit comments

Comments
 (0)