From patchwork Tue Dec 19 19:29:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kim, Dongwon" X-Patchwork-Id: 10124109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F19E76019C for ; Tue, 19 Dec 2017 19:38:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E39362924D for ; Tue, 19 Dec 2017 19:38:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7F9B2951E; Tue, 19 Dec 2017 19:38:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 952792924D for ; Tue, 19 Dec 2017 19:38:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 88A406E370; Tue, 19 Dec 2017 19:36:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 987916E34F for ; Tue, 19 Dec 2017 19:36:55 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2017 11:36:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,428,1508828400"; d="scan'208";a="4018614" Received: from downor-z87x-ud5h.fm.intel.com ([10.1.122.11]) by orsmga007.jf.intel.com with ESMTP; 19 Dec 2017 11:36:55 -0800 From: Dongwon Kim To: linux-kernel@vger.kernel.org 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 Cc: xen-devel@lists.xenproject.org, mateuszx.potrola@intel.com, dri-devel@lists.freedesktop.org, dongwon.kim@intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; }