From patchwork Mon Jun 24 16:53:59 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: 11013817 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 D250576 for ; Mon, 24 Jun 2019 16:54:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C109E2852C for ; Mon, 24 Jun 2019 16:54:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5E8128ABC; Mon, 24 Jun 2019 16:54:33 +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 6BD702852C for ; Mon, 24 Jun 2019 16:54:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7653B89D4B; Mon, 24 Jun 2019 16:54:27 +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 9A50A89CE1; Mon, 24 Jun 2019 16:54:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by netline-mail3.netline.ch (Postfix) with ESMTP id F2D342A604B; Mon, 24 Jun 2019 18:54:09 +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 mEliXgsGuDUD; Mon, 24 Jun 2019 18:54:09 +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 908362A6050; Mon, 24 Jun 2019 18:54:07 +0200 (CEST) Received: from daenzer by thor with local (Exim 4.92) (envelope-from ) id 1hfSEI-0003Zc-JA; 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 2/9] amdgpu: Add BO handle to table in amdgpu_bo_create Date: Mon, 24 Jun 2019 18:53:59 +0200 Message-Id: <20190624165406.13682-3-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 Simplifies its callers. dev->bo_table_mutex is now always held when amdgpu_bo_create is called (this was already the case in amdgpu_bo_import). Signed-off-by: Michel Dänzer --- amdgpu/amdgpu_bo.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 6c0b8517..5bdb8fe8 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -53,11 +53,18 @@ static int amdgpu_bo_create(amdgpu_device_handle dev, amdgpu_bo_handle *buf_handle) { struct amdgpu_bo *bo; + int r; bo = calloc(1, sizeof(struct amdgpu_bo)); if (!bo) return -ENOMEM; + r = handle_table_insert(&dev->bo_handles, handle, bo); + if (r) { + free(bo); + return r; + } + atomic_set(&bo->refcount, 1); bo->dev = dev; bo->alloc_size = size; @@ -89,19 +96,14 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle dev, if (r) goto out; + pthread_mutex_lock(&dev->bo_table_mutex); r = amdgpu_bo_create(dev, alloc_buffer->alloc_size, args.out.handle, buf_handle); + pthread_mutex_unlock(&dev->bo_table_mutex); if (r) { amdgpu_close_kms_handle(dev->fd, args.out.handle); - goto out; } - pthread_mutex_lock(&dev->bo_table_mutex); - r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle, - *buf_handle); - pthread_mutex_unlock(&dev->bo_table_mutex); - if (r) - amdgpu_bo_free(*buf_handle); out: return r; } @@ -363,15 +365,12 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev, if (r) goto free_bo_handle; - r = handle_table_insert(&dev->bo_handles, bo->handle, bo); - if (r) - goto free_bo_handle; if (flink_name) { bo->flink_name = flink_name; r = handle_table_insert(&dev->bo_flink_names, flink_name, bo); if (r) - goto remove_handle; + goto free_bo_handle; } @@ -380,8 +379,6 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev, pthread_mutex_unlock(&dev->bo_table_mutex); return 0; -remove_handle: - handle_table_remove(&dev->bo_handles, bo->handle); free_bo_handle: if (flink_name && open_arg.handle) amdgpu_close_kms_handle(dev->flink_fd, open_arg.handle); @@ -597,18 +594,13 @@ drm_public int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, if (r) goto out; + pthread_mutex_lock(&dev->bo_table_mutex); r = amdgpu_bo_create(dev, size, args.handle, buf_handle); + pthread_mutex_unlock(&dev->bo_table_mutex); if (r) { amdgpu_close_kms_handle(dev->fd, args.handle); - goto out; } - pthread_mutex_lock(&dev->bo_table_mutex); - r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle, - *buf_handle); - pthread_mutex_unlock(&dev->bo_table_mutex); - if (r) - amdgpu_bo_free(*buf_handle); out: return r; }