From patchwork Mon Jun 24 16:53:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michel_D=C3=A4nzer?= X-Patchwork-Id: 11013815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C66A576 for ; Mon, 24 Jun 2019 16:54:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B68F428AAF for ; Mon, 24 Jun 2019 16:54:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9C5E28BD0; Mon, 24 Jun 2019 16:54:32 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 51E8828AAF for ; Mon, 24 Jun 2019 16:54:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A520189D46; Mon, 24 Jun 2019 16:54:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from netline-mail3.netline.ch (mail.netline.ch [148.251.143.178]) by gabe.freedesktop.org (Postfix) with ESMTP id 932FB89C6B; Mon, 24 Jun 2019 16:54:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by netline-mail3.netline.ch (Postfix) with ESMTP id E565F2A6046; Mon, 24 Jun 2019 18:54:08 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at netline-mail3.netline.ch Received: from netline-mail3.netline.ch ([127.0.0.1]) by localhost (netline-mail3.netline.ch [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Q1_ecB8uGsFU; Mon, 24 Jun 2019 18:54:08 +0200 (CEST) Received: from thor (116.245.63.188.dynamic.wline.res.cust.swisscom.ch [188.63.245.116]) by netline-mail3.netline.ch (Postfix) with ESMTPSA id 494F72A6048; Mon, 24 Jun 2019 18:54:07 +0200 (CEST) Received: from daenzer by thor with local (Exim 4.92) (envelope-from ) id 1hfSEI-0003Za-I6; Mon, 24 Jun 2019 18:54:06 +0200 From: =?utf-8?q?Michel_D=C3=A4nzer?= To: amd-gfx@lists.freedesktop.org Subject: [PATCH libdrm 1/9] amdgpu: Pass file descriptor directly to amdgpu_close_kms_handle Date: Mon, 24 Jun 2019 18:53:58 +0200 Message-Id: <20190624165406.13682-2-michel@daenzer.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624165406.13682-1-michel@daenzer.net> References: <20190624165406.13682-1-michel@daenzer.net> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emil Velikov , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Michel Dänzer And propagate drmIoctl's return value. This allows replacing all remaining open-coded DRM_IOCTL_GEM_CLOSE ioctl calls with amdgpu_close_kms_handle calls. Signed-off-by: Michel Dänzer Reviewed-by: Emil Velikov --- amdgpu/amdgpu_bo.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 32ee358f..6c0b8517 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -39,13 +39,12 @@ #include "amdgpu_internal.h" #include "util_math.h" -static void amdgpu_close_kms_handle(amdgpu_device_handle dev, - uint32_t handle) +static int amdgpu_close_kms_handle(int fd, uint32_t handle) { struct drm_gem_close args = {}; args.handle = handle; - drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &args); + return drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &args); } static int amdgpu_bo_create(amdgpu_device_handle dev, @@ -93,7 +92,7 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle dev, r = amdgpu_bo_create(dev, alloc_buffer->alloc_size, args.out.handle, buf_handle); if (r) { - amdgpu_close_kms_handle(dev, args.out.handle); + amdgpu_close_kms_handle(dev->fd, args.out.handle); goto out; } @@ -214,11 +213,8 @@ static int amdgpu_bo_export_flink(amdgpu_bo_handle bo) bo->flink_name = flink.name; - if (bo->dev->flink_fd != bo->dev->fd) { - struct drm_gem_close args = {}; - args.handle = handle; - drmIoctl(bo->dev->flink_fd, DRM_IOCTL_GEM_CLOSE, &args); - } + if (bo->dev->flink_fd != bo->dev->fd) + amdgpu_close_kms_handle(bo->dev->flink_fd, handle); pthread_mutex_lock(&bo->dev->bo_table_mutex); r = handle_table_insert(&bo->dev->bo_flink_names, bo->flink_name, bo); @@ -261,7 +257,6 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev, struct amdgpu_bo_import_result *output) { struct drm_gem_open open_arg = {}; - struct drm_gem_close close_arg = {}; struct amdgpu_bo *bo = NULL; uint32_t handle = 0, flink_name = 0; uint64_t alloc_size = 0; @@ -345,12 +340,12 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev, close(dma_fd); if (r) goto free_bo_handle; - close_arg.handle = open_arg.handle; - r = drmIoctl(dev->flink_fd, DRM_IOCTL_GEM_CLOSE, - &close_arg); + r = amdgpu_close_kms_handle(dev->flink_fd, + open_arg.handle); if (r) goto free_bo_handle; } + open_arg.handle = 0; break; case amdgpu_bo_handle_type_dma_buf_fd: @@ -388,14 +383,13 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev, remove_handle: handle_table_remove(&dev->bo_handles, bo->handle); free_bo_handle: - if (flink_name && !close_arg.handle && open_arg.handle) { - close_arg.handle = open_arg.handle; - drmIoctl(dev->flink_fd, DRM_IOCTL_GEM_CLOSE, &close_arg); - } + if (flink_name && open_arg.handle) + amdgpu_close_kms_handle(dev->flink_fd, open_arg.handle); + if (bo) amdgpu_bo_free(bo); else - amdgpu_close_kms_handle(dev, handle); + amdgpu_close_kms_handle(dev->fd, handle); unlock: pthread_mutex_unlock(&dev->bo_table_mutex); return r; @@ -424,12 +418,13 @@ drm_public int amdgpu_bo_free(amdgpu_bo_handle buf_handle) amdgpu_bo_cpu_unmap(bo); } - amdgpu_close_kms_handle(dev, bo->handle); + amdgpu_close_kms_handle(dev->fd, bo->handle); pthread_mutex_destroy(&bo->cpu_access_mutex); free(bo); } pthread_mutex_unlock(&dev->bo_table_mutex); + return 0; } @@ -604,7 +599,7 @@ drm_public int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, r = amdgpu_bo_create(dev, size, args.handle, buf_handle); if (r) { - amdgpu_close_kms_handle(dev, args.handle); + amdgpu_close_kms_handle(dev->fd, args.handle); goto out; }