minigbm: gralloc0: Fix error handling in lock_ycbcr
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>
diff --git a/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc
index 79d1113..1ef9265 100644
--- a/cros_gralloc/gralloc0/gralloc0.cc
+++ b/cros_gralloc/gralloc0/gralloc0.cc
@@ -296,6 +296,8 @@
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 @@
ycbcr->chroma_step = 1;
break;
default:
+ mod->driver->unlock(handle);
return CROS_GRALLOC_ERROR_UNSUPPORTED;
}