From patchwork Tue Jul 14 14:10:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 6787511 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E1DAFC05AC for ; Tue, 14 Jul 2015 14:06:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 04F1420585 for ; Tue, 14 Jul 2015 14:06:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2AADB2055D for ; Tue, 14 Jul 2015 14:06:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 98F6C6EA26; Tue, 14 Jul 2015 07:06:04 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8F7476EA24; Tue, 14 Jul 2015 07:06:02 -0700 (PDT) Received: by wicmv11 with SMTP id mv11so15404583wic.1; Tue, 14 Jul 2015 07:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=adjXt0YP/Pf6L8Uv0pEjsqVAFEBlgE/Bs6FbwofypLM=; b=pHyun7/+CIRLU5JZcRsNX3PMiBPhLpgyP6vOmfxcRW9hyOo+hyKwQAyJqNBns+37/z Uzol/nxAf1NGyzffgOU0qg476PVS+TtaM8WAIv0oILzCk+k1JIvqhSWaKVHjpEDhYD2h LFkNInAg3IzQE3mojsP8YKNlTbnY3xFo3kn+/01ptOVSuZ9nwDLF6khV9hUJPov4ACBG p8LNqgsnU+OkAv+8TAFYNwBVp1IMDTqmDfcu+4Jikpe6K28hFESQrAtRjHQ916XC0VUx 21vBJ6UkT2kDKZWXzKDb1/zLkFo1tva88atM2WJ6/p9JH7zyW9vfVkkqYjtoZjzlDjeG MGpQ== X-Received: by 10.180.102.233 with SMTP id fr9mr34511248wib.3.1436882760853; Tue, 14 Jul 2015 07:06:00 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by smtp.gmail.com with ESMTPSA id fb3sm20979888wib.21.2015.07.14.07.05.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Jul 2015 07:05:59 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 1/4] freedreno: zero is a valid fd number, treat it as such Date: Tue, 14 Jul 2015 15:10:02 +0100 Message-Id: <1436883005-6163-1-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.4.5 Cc: freedreno@lists.freedesktop.org, emil.l.velikov@gmail.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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Abeit quite unlikely to get hit by this bug here, let just fix it. v2: Correct conditional (do not call ioctl(DRM_IOCTL_PRIME_HANDLE_TO_FD) when we already have the fd). v3: Fix kgsl_pipe.c, suggested by Thierry. Cc: freedreno@lists.freedesktop.org Cc: Rob Clark Signed-off-by: Emil Velikov Reviewed-by: Thierry Reding --- freedreno/freedreno_bo.c | 6 +++--- freedreno/kgsl/kgsl_bo.c | 1 + freedreno/kgsl/kgsl_pipe.c | 2 +- freedreno/msm/msm_bo.c | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/freedreno/freedreno_bo.c b/freedreno/freedreno_bo.c index 517a2f8..eec218c 100644 --- a/freedreno/freedreno_bo.c +++ b/freedreno/freedreno_bo.c @@ -285,9 +285,9 @@ void fd_bo_del(struct fd_bo *bo) if (!atomic_dec_and_test(&bo->refcnt)) return; - if (bo->fd) { + if (bo->fd >= 0) { close(bo->fd); - bo->fd = 0; + bo->fd = -1; } pthread_mutex_lock(&table_lock); @@ -372,7 +372,7 @@ uint32_t fd_bo_handle(struct fd_bo *bo) int fd_bo_dmabuf(struct fd_bo *bo) { - if (!bo->fd) { + if (bo->fd < 0) { struct drm_prime_handle req = { .handle = bo->handle, .flags = DRM_CLOEXEC, diff --git a/freedreno/kgsl/kgsl_bo.c b/freedreno/kgsl/kgsl_bo.c index 15c3ff5..3407c76 100644 --- a/freedreno/kgsl/kgsl_bo.c +++ b/freedreno/kgsl/kgsl_bo.c @@ -168,6 +168,7 @@ drm_private struct fd_bo * kgsl_bo_from_handle(struct fd_device *dev, bo = &kgsl_bo->base; bo->funcs = &funcs; + bo->fd = -1; for (i = 0; i < ARRAY_SIZE(kgsl_bo->list); i++) list_inithead(&kgsl_bo->list[i]); diff --git a/freedreno/kgsl/kgsl_pipe.c b/freedreno/kgsl/kgsl_pipe.c index fc76b2b..08c87a6 100644 --- a/freedreno/kgsl/kgsl_pipe.c +++ b/freedreno/kgsl/kgsl_pipe.c @@ -101,7 +101,7 @@ static void kgsl_pipe_destroy(struct fd_pipe *pipe) if (kgsl_pipe->drawctxt_id) ioctl(kgsl_pipe->fd, IOCTL_KGSL_DRAWCTXT_DESTROY, &req); - if (kgsl_pipe->fd) + if (kgsl_pipe->fd >= 0) close(kgsl_pipe->fd); free(kgsl_pipe); diff --git a/freedreno/msm/msm_bo.c b/freedreno/msm/msm_bo.c index fbd82df..3f5b6d0 100644 --- a/freedreno/msm/msm_bo.c +++ b/freedreno/msm/msm_bo.c @@ -137,6 +137,7 @@ drm_private struct fd_bo * msm_bo_from_handle(struct fd_device *dev, bo = &msm_bo->base; bo->funcs = &funcs; + bo->fd = -1; for (i = 0; i < ARRAY_SIZE(msm_bo->list); i++) list_inithead(&msm_bo->list[i]);