Get size of dma buf with gem_open only when lseek is failed 96/295996/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 18 Jul 2023 05:38:32 +0000 (14:38 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Tue, 18 Jul 2023 05:39:17 +0000 (14:39 +0900)
Change-Id: I889d175c61d1b58c7503ccbe902cc3eca3eea184

src/tbm_backend_dumb.c

index d8c91cb4b104277b6b0b5687354f0e95752d55f0..931d71ec1745030e592a4e227ea95abf96c6da59 100644 (file)
@@ -755,28 +755,28 @@ tbm_dumb_bufmgr_import_fd(hal_tbm_bufmgr *bufmgr, hal_tbm_fd key, hal_tbm_error
         * kernels will just fail, in which case we fall back to the
         * provided (estimated or guess size). */
        real_size = lseek(key, 0, SEEK_END);
+       if (real_size == -1) {
+               /* Open the same GEM object only for finding out its size */
+               open_arg.name = name;
+               if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_GEM_OPEN, &open_arg)) {
+                       TBM_BACKEND_ERR("fail to DRM_IOCTL_GEM_OPEN gem:%d name:%d (%m)",
+                                       gem, name);
+                       if (error)
+                               *error = HAL_TBM_ERROR_INVALID_OPERATION;
+                       return NULL;
+               }
 
-       /* Open the same GEM object only for finding out its size */
-       open_arg.name = name;
-       if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_GEM_OPEN, &open_arg)) {
-               TBM_BACKEND_ERR("fail to DRM_IOCTL_GEM_OPEN gem:%d name:%d (%m)",
-                               gem, name);
-               if (error)
-                       *error = HAL_TBM_ERROR_INVALID_OPERATION;
-               return NULL;
-       }
-
-       /* Free gem handle to avoid a memory leak*/
-       close_arg.handle = open_arg.handle;
-       if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_GEM_CLOSE, &close_arg)) {
-               TBM_BACKEND_ERR("fail to DRM_IOCTL_GEM_CLOSE gem:%d (%m)", open_arg.handle);
-               if (error)
-                       *error = HAL_TBM_ERROR_INVALID_OPERATION;
-               return NULL;
-       }
+               /* Free gem handle to avoid a memory leak*/
+               close_arg.handle = open_arg.handle;
+               if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_GEM_CLOSE, &close_arg)) {
+                       TBM_BACKEND_ERR("fail to DRM_IOCTL_GEM_CLOSE gem:%d (%m)", open_arg.handle);
+                       if (error)
+                               *error = HAL_TBM_ERROR_INVALID_OPERATION;
+                       return NULL;
+               }
 
-       if (real_size == -1)
                real_size = open_arg.size;
+       }
 
        bo_data = calloc(1, sizeof(struct _tbm_dumb_bo));
        if (!bo_data) {