drm/syncobj: add a new helper drm_syncobj_get_fd
authorMarek Olšák <marek.olsak@amd.com>
Tue, 12 Sep 2017 20:42:13 +0000 (22:42 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 6 Oct 2017 20:47:53 +0000 (16:47 -0400)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/drm_syncobj.c
include/drm/drm_syncobj.h

index 0bb174109b96988946dc1ce38fb2be21b9343aa8..62adc7acafcc3d230f90da46bd1092e818dda8a9 100644 (file)
@@ -386,33 +386,38 @@ static int drm_syncobj_alloc_file(struct drm_syncobj *syncobj)
        return 0;
 }
 
-static int drm_syncobj_handle_to_fd(struct drm_file *file_private,
-                                   u32 handle, int *p_fd)
+int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd)
 {
-       struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
        int ret;
        int fd;
 
-       if (!syncobj)
-               return -EINVAL;
-
        fd = get_unused_fd_flags(O_CLOEXEC);
-       if (fd < 0) {
-               drm_syncobj_put(syncobj);
+       if (fd < 0)
                return fd;
-       }
 
        if (!syncobj->file) {
                ret = drm_syncobj_alloc_file(syncobj);
-               if (ret)
-                       goto out_put_fd;
+               if (ret) {
+                       put_unused_fd(fd);
+                       return ret;
+               }
        }
        fd_install(fd, syncobj->file);
-       drm_syncobj_put(syncobj);
        *p_fd = fd;
        return 0;
-out_put_fd:
-       put_unused_fd(fd);
+}
+EXPORT_SYMBOL(drm_syncobj_get_fd);
+
+static int drm_syncobj_handle_to_fd(struct drm_file *file_private,
+                                   u32 handle, int *p_fd)
+{
+       struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
+       int ret;
+
+       if (!syncobj)
+               return -EINVAL;
+
+       ret = drm_syncobj_get_fd(syncobj, p_fd);
        drm_syncobj_put(syncobj);
        return ret;
 }
index e7f0035bb8f8fe556aa346bd113b1f072dc799c2..43e2f382d2f0ab9c7571c385bde82373eb898088 100644 (file)
@@ -140,5 +140,6 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
                       struct dma_fence *fence);
 int drm_syncobj_get_handle(struct drm_file *file_private,
                           struct drm_syncobj *syncobj, u32 *handle);
+int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);
 
 #endif