Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753507AbdLSTnL (ORCPT ); Tue, 19 Dec 2017 14:43:11 -0500 Received: from mga01.intel.com ([192.55.52.88]:17651 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753229AbdLSTg6 (ORCPT ); Tue, 19 Dec 2017 14:36:58 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,428,1508828400"; d="scan'208";a="4018614" From: Dongwon Kim To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, xen-devel@lists.xenproject.org, mateuszx.potrola@intel.com, dongwon.kim@intel.com Subject: [RFC PATCH 39/60] hyper_dmabuf: correcting DMA-BUF clean-up order Date: Tue, 19 Dec 2017 11:29:55 -0800 Message-Id: <1513711816-2618-39-git-send-email-dongwon.kim@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> References: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2787 Lines: 96 Reordering clean-up procedure Signed-off-by: Dongwon Kim --- drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 37 +++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c index b77b156..2ff2c145 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c @@ -148,21 +148,24 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data) attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device); if (IS_ERR(attachment)) { dev_err(hyper_dmabuf_private.device, "Cannot get attachment\n"); - return PTR_ERR(attachment); + ret = PTR_ERR(attachment); + goto fail_attach; } sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL); if (IS_ERR(sgt)) { dev_err(hyper_dmabuf_private.device, "Cannot map attachment\n"); - return PTR_ERR(sgt); + ret = PTR_ERR(sgt); + goto fail_map_attachment; } sgt_info = kcalloc(1, sizeof(*sgt_info), GFP_KERNEL); if(!sgt_info) { dev_err(hyper_dmabuf_private.device, "no more space left\n"); - return -ENOMEM; + ret = -ENOMEM; + goto fail_sgt_info_creation; } sgt_info->hid = hyper_dmabuf_get_hid(); @@ -171,8 +174,8 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data) if(sgt_info->hid.id == -1) { dev_err(hyper_dmabuf_private.device, "exceeds allowed number of dmabuf to be exported\n"); - /* TODO: Cleanup sgt */ - return -ENOMEM; + ret = -ENOMEM; + goto fail_sgt_info_creation; } /* TODO: We might need to consider using port number on event channel? */ @@ -286,6 +289,8 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data) return ret; +/* Clean-up if error occurs */ + fail_send_request: kfree(req); @@ -293,20 +298,26 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data) hyper_dmabuf_remove_exported(sgt_info->hid); fail_export: - dma_buf_unmap_attachment(sgt_info->active_attached->attach, - sgt_info->active_sgts->sgt, - DMA_BIDIRECTIONAL); - dma_buf_detach(sgt_info->dma_buf, sgt_info->active_attached->attach); - dma_buf_put(sgt_info->dma_buf); - kfree(sgt_info->va_vmapped); + fail_map_va_vmapped: kfree(sgt_info->va_kmapped); + fail_map_va_kmapped: - kfree(sgt_info->active_sgts); -fail_map_active_sgts: kfree(sgt_info->active_attached); + fail_map_active_attached: + kfree(sgt_info->active_sgts); + +fail_map_active_sgts: +fail_sgt_info_creation: + dma_buf_unmap_attachment(attachment, sgt, DMA_BIDIRECTIONAL); + +fail_map_attachment: + dma_buf_detach(dma_buf, attachment); + +fail_attach: + dma_buf_put(dma_buf); return ret; } -- 2.7.4