OSDN Git Service

minigbm: gralloc0: Fix error handling in lock_ycbcr
authorTomasz Figa <tfiga@chromium.org>
Wed, 5 Jul 2017 08:50:18 +0000 (17:50 +0900)
committerchrome-bot <chrome-bot@chromium.org>
Tue, 11 Jul 2017 07:38:59 +0000 (00:38 -0700)
cros_gralloc_lock_ycbcr() obtains the mapping first and then fills in
the android_ycbcr struct. However the last step can fail if the backing
format is not included in the switch statement. In this case the function
returns without releasing the mapping.

Fix it by calling mod->drv->unlock() before returning, when the format
is unsupported. Also do not attempt to fill in the struct if the earlier
mod->drv->lock(() fails.

BUG=b:32077885
TEST=lock_ycbcr() fails properly for HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED
 when it is backed by a RGBX_8888 buffer on Poppy.

Change-Id: I0b8cf91c578595a1b6ddc6e21009a8a84b8ac4de
Reviewed-on: https://chromium-review.googlesource.com/544486
Commit-Ready: Tomasz Figa <tfiga@chromium.org>
Tested-by: Tomasz Figa <tfiga@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
cros_gralloc/gralloc0/gralloc0.cc

index 79d1113..1ef9265 100644 (file)
@@ -296,6 +296,8 @@ static int gralloc0_lock_ycbcr(struct gralloc_module_t const *module, buffer_han
        fence = -1;
        flags = gralloc0_convert_flags(usage);
        ret = mod->driver->lock(handle, fence, flags, addr);
+       if (ret)
+               return ret;
 
        switch (hnd->format) {
        case DRM_FORMAT_NV12:
@@ -316,6 +318,7 @@ static int gralloc0_lock_ycbcr(struct gralloc_module_t const *module, buffer_han
                ycbcr->chroma_step = 1;
                break;
        default:
+               mod->driver->unlock(handle);
                return CROS_GRALLOC_ERROR_UNSUPPORTED;
        }