From patchwork Fri Aug 5 02:24:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9264711 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 CFE8960467 for ; Fri, 5 Aug 2016 02:24:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0C9D283AC for ; Fri, 5 Aug 2016 02:24:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B34FC28409; Fri, 5 Aug 2016 02:24: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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DF1F283AC for ; Fri, 5 Aug 2016 02:24:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 635F66EAC9; Fri, 5 Aug 2016 02:24:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yb0-f194.google.com (mail-yb0-f194.google.com [209.85.213.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id ED6126EAC7 for ; Fri, 5 Aug 2016 02:24:42 +0000 (UTC) Received: by mail-yb0-f194.google.com with SMTP id g133so1070760ybf.2 for ; Thu, 04 Aug 2016 19:24:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=te9JsCKiipmykE8EF+vdtng8IoweijLeNHQ4S04m4Pc=; b=lmOKETt3YqXBuU6wYbuj8+Ibk3/csHghtPHfLDTKZDzfKkFyJRVDEbpftTeACeH7No SeSlljGptHXix4thXV8J+FngeZTN0uJ1lorX1l5R2jJBqYRdJwxPxusgi6MMa4J8suW9 6dt1QqufIvnx3B61rcFHQy9kgBEPQ4NfjPS8x1/7sdGHtvu3tPfk/yuVKIs/iAsk5hDO 73wsF8nDLAz3xhFBXhhMBbYrcKvAiwlZMwt9E/cONXlC939VzlanQWFbB59ydhUrvl0j qt1NjRSnhAUL8MFxYau0yZ1CbNUm4nC3EoK7O0mi1SDuvibjPfgklh7Jnj62mgO7ON8r o8wg== X-Gm-Message-State: AEkoouvn9vY1vMPLrQzggZO/sANzcGzvBEIPM/U0RuthT7g7FA3NcJQ9Um3IHF68RhNObQ== X-Received: by 10.37.77.86 with SMTP id a83mr35162875ybb.169.1470363880654; Thu, 04 Aug 2016 19:24:40 -0700 (PDT) Received: from jade.localdomain ([201.82.189.183]) by smtp.gmail.com with ESMTPSA id j189sm6894648ywc.32.2016.08.04.19.24.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 19:24:39 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH v5 3/5] dma-buf/sync_file: add sync_file_get_fence() Date: Thu, 4 Aug 2016 23:24:12 -0300 Message-Id: <1470363854-7846-3-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1470363854-7846-1-git-send-email-gustavo@padovan.org> References: <1470363854-7846-1-git-send-email-gustavo@padovan.org> MIME-Version: 1.0 Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , linux-kernel@vger.kernel.org, laurent.pinchart@ideasonboard.com, Gustavo Padovan , John Harrison , m.chehab@samsung.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 From: Gustavo Padovan Creates a function that given an sync file descriptor returns a fence containing all fences in the sync_file. v2: Comments by Daniel Vetter - Adapt to new version of fence_collection_init() - Hold a reference for the fence we return v3: - Adapt to use fput() directly - rename to sync_file_get_fence() as we always return one fence v4: Adapt to use fence_array v5: set fence through fence_get() Signed-off-by: Gustavo Padovan Reviewed-by: Chris Wilson Acked-by: Christian König --- drivers/dma-buf/sync_file.c | 23 +++++++++++++++++++++++ include/linux/sync_file.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index ac9c250..2873760 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -116,6 +116,29 @@ err: return NULL; } +/** + * sync_file_get_fence - get the fence related to the sync_file fd + * @fd: sync_file fd to get the fence from + * + * Ensures @fd references a valid sync_file and returns a fence that + * represents all fence in the sync_file. On error NULL is returned. + */ +struct fence *sync_file_get_fence(int fd) +{ + struct sync_file *sync_file; + struct fence *fence; + + sync_file = sync_file_fdget(fd); + if (!sync_file) + return NULL; + + fence = fence_get(sync_file->fence); + fput(sync_file->file); + + return fence; +} +EXPORT_SYMBOL(sync_file_get_fence); + static int sync_file_set_fence(struct sync_file *sync_file, struct fence **fences, int num_fences) { diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h index 2efc5ec..f7de5a0 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -46,5 +46,6 @@ struct sync_file { }; struct sync_file *sync_file_create(struct fence *fence); +struct fence *sync_file_get_fence(int fd); #endif /* _LINUX_SYNC_H */