diff options
author | Vaibhav Jain <vaibhav@linux.vnet.ibm.com> | 2015-08-25 01:34:48 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2015-08-26 23:51:18 -0400 |
commit | a6897f39660cc07fa78b4459d82f12b07abb50b1 (patch) | |
tree | 65e2cdb08682a98de731de244ca79656972e327c /drivers/misc/cxl/irq.c | |
parent | f47f966fbe0aaff4ebbdb83d95acdfa5d3c20477 (diff) |
cxl: Release irqs if memory allocation fails
This minor patch plugs a potential irq leak in case of a memory
allocation failure inside function the afu_allocate_irqs. Presently the
irqs allocated to the context gets leaked if allocation of either
one of context irq_bitmap or irq_names fails.
Signed-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/misc/cxl/irq.c')
-rw-r--r-- | drivers/misc/cxl/irq.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/misc/cxl/irq.c b/drivers/misc/cxl/irq.c index 72bf45ae3806..583b42afeda2 100644 --- a/drivers/misc/cxl/irq.c +++ b/drivers/misc/cxl/irq.c | |||
@@ -430,6 +430,9 @@ int afu_allocate_irqs(struct cxl_context *ctx, u32 count) | |||
430 | int rc, r, i, j = 1; | 430 | int rc, r, i, j = 1; |
431 | struct cxl_irq_name *irq_name; | 431 | struct cxl_irq_name *irq_name; |
432 | 432 | ||
433 | /* Initialize the list head to hold irq names */ | ||
434 | INIT_LIST_HEAD(&ctx->irq_names); | ||
435 | |||
433 | if ((rc = cxl_alloc_irq_ranges(&ctx->irqs, ctx->afu->adapter, count))) | 436 | if ((rc = cxl_alloc_irq_ranges(&ctx->irqs, ctx->afu->adapter, count))) |
434 | return rc; | 437 | return rc; |
435 | 438 | ||
@@ -441,13 +444,12 @@ int afu_allocate_irqs(struct cxl_context *ctx, u32 count) | |||
441 | ctx->irq_bitmap = kcalloc(BITS_TO_LONGS(count), | 444 | ctx->irq_bitmap = kcalloc(BITS_TO_LONGS(count), |
442 | sizeof(*ctx->irq_bitmap), GFP_KERNEL); | 445 | sizeof(*ctx->irq_bitmap), GFP_KERNEL); |
443 | if (!ctx->irq_bitmap) | 446 | if (!ctx->irq_bitmap) |
444 | return -ENOMEM; | 447 | goto out; |
445 | 448 | ||
446 | /* | 449 | /* |
447 | * Allocate names first. If any fail, bail out before allocating | 450 | * Allocate names first. If any fail, bail out before allocating |
448 | * actual hardware IRQs. | 451 | * actual hardware IRQs. |
449 | */ | 452 | */ |
450 | INIT_LIST_HEAD(&ctx->irq_names); | ||
451 | for (r = 1; r < CXL_IRQ_RANGES; r++) { | 453 | for (r = 1; r < CXL_IRQ_RANGES; r++) { |
452 | for (i = 0; i < ctx->irqs.range[r]; i++) { | 454 | for (i = 0; i < ctx->irqs.range[r]; i++) { |
453 | irq_name = kmalloc(sizeof(struct cxl_irq_name), | 455 | irq_name = kmalloc(sizeof(struct cxl_irq_name), |
@@ -469,6 +471,7 @@ int afu_allocate_irqs(struct cxl_context *ctx, u32 count) | |||
469 | return 0; | 471 | return 0; |
470 | 472 | ||
471 | out: | 473 | out: |
474 | cxl_release_irq_ranges(&ctx->irqs, ctx->afu->adapter); | ||
472 | afu_irq_name_free(ctx); | 475 | afu_irq_name_free(ctx); |
473 | return -ENOMEM; | 476 | return -ENOMEM; |
474 | } | 477 | } |