From patchwork Mon Jul 13 13:52:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 6779391 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BA92B9F2F0 for ; Mon, 13 Jul 2015 13:48:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DBB6420377 for ; Mon, 13 Jul 2015 13:47:59 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1357A2037C for ; Mon, 13 Jul 2015 13:47:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 87AF16E331; Mon, 13 Jul 2015 06:47:57 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75A4A6E321; Mon, 13 Jul 2015 06:47:56 -0700 (PDT) Received: by wgkl9 with SMTP id l9so26417293wgk.1; Mon, 13 Jul 2015 06:47:55 -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:in-reply-to:references; bh=pT2VB+8ZSX8AYFYq0Tj/vZUAdgr2rPVRqIPMsIEPqgI=; b=Xf/5sdQ8VMuXEEuE/HHRumcM3xQlAYGhNCjhihx7GiQ37Frw57y3blShKU4ONptcfM B6IQZ9cX+YJJ/nRrAdvLiICCHw97HXo2SHL1saVOE3reA18+KB6V/tncxdgzSKmjxEhy DRdp7R9AHydcY01RtqZ/XS4DFVyBn9RRFbSaVuPYZLXlrdEJerg5n7rJbM6StXKcqcyG /DeMF/cOLBG3OgUpkO0T6XTdfktUrlj+hMXCBE5ivmWQL6E1OoeW0G1ZA4iiV8zdnzu3 ej/lJwhVIk/cYoIQ3UUEyS9mVFq56/fdpTe1RKoz++ZtxGOWCnbwbhbe8T8TBM7GL36x UouQ== X-Received: by 10.180.76.232 with SMTP id n8mr23799367wiw.72.1436795275030; Mon, 13 Jul 2015 06:47:55 -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 v20sm29326977wjw.17.2015.07.13.06.47.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Jul 2015 06:47:54 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm] freedreno: zero is a valid fd number, treat it as such Date: Mon, 13 Jul 2015 14:52:09 +0100 Message-Id: <1436795529-19701-1-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.4.5 In-Reply-To: <1436794745-19525-1-git-send-email-emil.l.velikov@gmail.com> References: <1436794745-19525-1-git-send-email-emil.l.velikov@gmail.com> 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). 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/msm/msm_bo.c | 1 + 3 files changed, 5 insertions(+), 3 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/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]);