Path: csiph.com!eternal-september.org!feeder.eternal-september.org!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!newsfeed.CARNet.hr!news.spin.it!bofh.it!news.nic.it!robomod From: "Ian Munsie" Newsgroups: linux.kernel Subject: [PATCH 1/2] cxl: Fix + cleanup error paths in cxl_dev_context_init Date: Thu, 27 Aug 2015 12:00:04 +0200 Message-ID: X-Original-To: mpe X-Helo: d23dlp02.au.ibm.com X-Mailfrom: imunsie@au1.ibm.com X-Rcptto: linux-kernel@vger.kernel.org X-Mailer: git-send-email 2.1.4 X-Tm-As-Mml: disable X-Content-Scanned: Fidelis XPS MAILER X-Cbid: 15082709-1618-0000-0000-000002AC4732 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 59 Organization: linux.* mail to news gateway X-Original-Cc: mikey , linux-kernel , linuxppc-dev , Matt Ochs , Ian Munsie X-Original-Date: Thu, 27 Aug 2015 19:50:18 +1000 X-Original-Message-ID: <1440669019-23800-1-git-send-email-imunsie@au.ibm.com> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1214446 From: Ian Munsie 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 --- 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/