Skip to content

Commit 1e41a29

Browse files
committed
bufmgr: use off_t for lseek result in PRIME import toavoid 64-bit Truncation
1 parent 78a9585 commit 1e41a29

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

media_softlet/linux/common/os/i915/mos_bufmgr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,11 +3501,11 @@ mos_gem_bo_create_from_prime(struct mos_bufmgr *bufmgr, struct mos_drm_bo_alloc_
35013501
* later, we can lseek on the prime fd to get the size. Older
35023502
* kernels will just fail, in which case we fall back to the
35033503
* provided (estimated or guess size). */
3504-
ret = lseek(prime_fd, 0, SEEK_END);
3505-
if (ret != -1)
3506-
bo_gem->bo.size = ret;
3504+
off_t sz =lseek(prime_fd,0,SEEK_END);
3505+
if(sz>= 0)
3506+
bo_gem->bo.size=(unsigned long)sz;
35073507
else
3508-
bo_gem->bo.size = size;
3508+
bo_gem->bo.size = (unsigned long)size;
35093509

35103510
bo_gem->bo.handle = handle;
35113511
bo_gem->bo.bufmgr = bufmgr;

media_softlet/linux/common/os/i915_production/mos_bufmgr.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,19 +3493,17 @@ mos_gem_bo_create_from_prime(struct mos_bufmgr *bufmgr, struct mos_drm_bo_alloc_
34933493
* later, we can lseek on the prime fd to get the size. Older
34943494
* kernels will just fail, in which case we fall back to the
34953495
* provided (estimated or guess size). */
3496-
ret = lseek(prime_fd, 0, SEEK_END);
3497-
if (ret != -1)
3498-
bo_gem->bo.size = ret;
3496+
off_t sz=lseek(prime_fd,0, SEEK_END);
3497+
if(sz>=0) bo_gem->bo.size=(unsigned long)sz;
34993498
else
3500-
bo_gem->bo.size = size;
3499+
bo_gem->bo.size=(unsigned long)size;
35013500

35023501
bo_gem->bo.handle = handle;
35033502
bo_gem->bo.bufmgr = bufmgr;
35043503

35053504
bo_gem->gem_handle = handle;
35063505

35073506
atomic_set(&bo_gem->refcount, 1);
3508-
35093507
bo_gem->name = alloc_prime->name;
35103508
bo_gem->validate_index = -1;
35113509
bo_gem->reloc_tree_fences = 0;

0 commit comments

Comments
 (0)