Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1214446 > unrolled thread

[PATCH 1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init

Started by"Ian Munsie" <imunsie@au1.ibm.com>
First post2015-08-27 12:00 +0200
Last post2015-08-30 23:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init "Ian Munsie" <imunsie@au1.ibm.com> - 2015-08-27 12:00 +0200
    Re: [1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init Michael Ellerman <mpe@ellerman.id.au> - 2015-08-30 23:30 +0200

#1214446 — [PATCH 1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init

From"Ian Munsie" <imunsie@au1.ibm.com>
Date2015-08-27 12:00 +0200
Subject[PATCH 1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init
Message-ID<q228r-RU-35@gated-at.bofh.it>
From: Ian Munsie <imunsie@au1.ibm.com>

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>
---
 drivers/misc/cxl/api.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index f49e3e5..005adc7 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);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1215977 — Re: [1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init

FromMichael Ellerman <mpe@ellerman.id.au>
Date2015-08-30 23:30 +0200
SubjectRe: [1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init
Message-ID<q3ikN-4at-11@gated-at.bofh.it>
In reply to#1214446
On Thu, 2015-27-08 at 09:50:18 UTC, Ian Munsie wrote:
> From: Ian Munsie <imunsie@au1.ibm.com>
> 
> 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>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/af2a50bb0ce1ca7a9c478481

cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web