gallium: fix return value check
authorMartina Kollarova <martina.kollarova@intel.com>
Thu, 8 Sep 2016 12:12:42 +0000 (15:12 +0300)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 14 Sep 2016 13:36:43 +0000 (14:36 +0100)
A possible error (-1) was being lost because it was first converted to an
unsigned int and only then checked.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Signed-off-by: Martina Kollarova <martina.kollarova@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c

index 07eca990d04316c645e59b03f7cc69c80a97d0b2..22e1c936ac53aaf53bf06e49ed04d34c860c5c6e 100644 (file)
@@ -252,18 +252,18 @@ kms_sw_displaytarget_add_from_prime(struct kms_sw_winsys *kms_sw, int fd,
    if (!kms_sw_dt)
       return NULL;
 
+   off_t lseek_ret = lseek(fd, 0, SEEK_END);
+   if (lseek_ret == -1) {
+      FREE(kms_sw_dt);
+      return NULL;
+   }
+   kms_sw_dt->size = lseek_ret;
    kms_sw_dt->ref_count = 1;
    kms_sw_dt->handle = handle;
-   kms_sw_dt->size = lseek(fd, 0, SEEK_END);
    kms_sw_dt->width = width;
    kms_sw_dt->height = height;
    kms_sw_dt->stride = stride;
 
-   if (kms_sw_dt->size == (off_t)-1) {
-      FREE(kms_sw_dt);
-      return NULL;
-   }
-
    lseek(fd, 0, SEEK_SET);
 
    list_add(&kms_sw_dt->link, &kms_sw->bo_list);