gbm: Use unsigned for BO offset getter
authorDaniel Stone <daniels@collabora.com>
Thu, 23 Mar 2017 15:09:49 +0000 (15:09 +0000)
committerDaniel Stone <daniels@collabora.com>
Thu, 23 Mar 2017 15:28:41 +0000 (15:28 +0000)
The actual offset returned is uint32_t, however int64_t was used as the
return type from gbm_bo_get_offset to allow negative returns to signal
errors to the caller.

In case of an error getting the offset, the user will also be unable to
get the handle/FD, and thus have nothing to offset into. This means that
returning 0 as an error value is harmless, allowing us to change the
return type to uint32_t in order to avoid signed/unsigned confusion in
callers.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Cc: Ben Widawsky <ben@bwidawsk.net>
Cc: Jason Ekstrand <jason@jlekstrand.net>
src/gbm/backends/dri/gbm_dri.c
src/gbm/main/gbm.c
src/gbm/main/gbm.h
src/gbm/main/gbmint.h

index 84b4dd88530ae910ed04c424fd39b1ea9b657b41..6b89229cdc0e3d024153e00080b0fa0aa6306d8a 100644 (file)
@@ -710,22 +710,23 @@ gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
    return (uint32_t)stride;
 }
 
    return (uint32_t)stride;
 }
 
-static int64_t
+static uint32_t
 gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
 {
    struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
    struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
    int offset = 0;
 
 gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
 {
    struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
    struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
    int offset = 0;
 
-   if (!dri->image || dri->image->base.version < 13 || !dri->image->fromPlanar) {
-      errno = ENOSYS;
-      return -1;
-   }
+   /* These error cases do not actually return an error code, as the user
+    * will also fail to obtain the handle/FD from the BO. In that case, the
+    * offset is irrelevant, as they have no buffer to offset into, so
+    * returning 0 is harmless.
+    */
+   if (!dri->image || dri->image->base.version < 13 || !dri->image->fromPlanar)
+      return 0;
 
 
-   if (plane >= get_number_planes(dri, bo->image)) {
-      errno = EINVAL;
-      return -2;
-   }
+   if (plane >= get_number_planes(dri, bo->image))
+      return 0;
 
     /* Dumb images have no offset */
    if (bo->image == NULL) {
 
     /* Dumb images have no offset */
    if (bo->image == NULL) {
index 19dc5db901a3f7866437b43581f173744ff59cb5..79d78b763e67e1e5a1603f2ede91f9633976dcef 100644 (file)
@@ -203,7 +203,7 @@ gbm_bo_get_format(struct gbm_bo *bo)
  * \param bo The buffer object
  * \return The offset
  */
  * \param bo The buffer object
  * \return The offset
  */
-GBM_EXPORT int64_t
+GBM_EXPORT uint32_t
 gbm_bo_get_offset(struct gbm_bo *bo, int plane)
 {
    return bo->gbm->bo_get_offset(bo, plane);
 gbm_bo_get_offset(struct gbm_bo *bo, int plane)
 {
    return bo->gbm->bo_get_offset(bo, plane);
index a774b509510ce987f09432d5b46cb808fc68fd73..b52137ed01d4cd7d1443b926c48b10be6aad2812 100644 (file)
@@ -315,7 +315,7 @@ gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
 uint32_t
 gbm_bo_get_format(struct gbm_bo *bo);
 
 uint32_t
 gbm_bo_get_format(struct gbm_bo *bo);
 
-int64_t
+uint32_t
 gbm_bo_get_offset(struct gbm_bo *bo, int plane);
 
 struct gbm_device *
 gbm_bo_get_offset(struct gbm_bo *bo, int plane);
 
 struct gbm_device *
index 5ad85cc80fff21521907544fb6ec51cf1e964c1b..c27a7a560aee468056d127e172e2f5a98a41d2a6 100644 (file)
@@ -81,7 +81,7 @@ struct gbm_device {
    int (*bo_get_planes)(struct gbm_bo *bo);
    union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
    uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);
    int (*bo_get_planes)(struct gbm_bo *bo);
    union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
    uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);
-   int64_t (*bo_get_offset)(struct gbm_bo *bo, int plane);
+   uint32_t (*bo_get_offset)(struct gbm_bo *bo, int plane);
    uint64_t (*bo_get_modifier)(struct gbm_bo *bo);
    void (*bo_destroy)(struct gbm_bo *bo);
 
    uint64_t (*bo_get_modifier)(struct gbm_bo *bo);
    void (*bo_destroy)(struct gbm_bo *bo);