summaryrefslogtreecommitdiff
path: root/drivers/misc/cxl
diff options
context:
space:
mode:
authorIan Munsie <imunsie@au1.ibm.com>2015-08-27 19:50:18 +1000
committerMichael Ellerman <mpe@ellerman.id.au>2015-08-30 18:47:26 +1000
commitaf2a50bb0ce1ca7a9c4784813419c922bf2285df (patch)
tree51400c2c6e83151f08374a4de45297347e2b7788 /drivers/misc/cxl
parent259800135c654a098d9f0adfdd3d1f20eef1f231 (diff)
cxl: Fix + cleanup error paths in cxl_dev_context_init
If the cxl_context_alloc() call fails, we return immediately without releasing the reference on the AFU device, allowing it to leak. This patch switches to using goto style error handling so that the device is released in common code for both error paths, and will also simplify things if we add additional initialisation in this function in the future. Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/misc/cxl')
-rw-r--r--drivers/misc/cxl/api.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index f49e3e5db58d..005adc7d33a2 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -25,19 +25,24 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
get_device(&afu->dev);
ctx = cxl_context_alloc();
- if (IS_ERR(ctx))
- return ctx;
+ if (IS_ERR(ctx)) {
+ rc = PTR_ERR(ctx);
+ goto err_dev;
+ }
/* Make it a slave context. We can promote it later? */
rc = cxl_context_init(ctx, afu, false, NULL);
- if (rc) {
- kfree(ctx);
- put_device(&afu->dev);
- return ERR_PTR(-ENOMEM);
- }
+ if (rc)
+ goto err_ctx;
cxl_assign_psn_space(ctx);
return ctx;
+
+err_ctx:
+ kfree(ctx);
+err_dev:
+ put_device(&afu->dev);
+ return ERR_PTR(rc);
}
EXPORT_SYMBOL_GPL(cxl_dev_context_init);