hwc: Check for the validity of the fb layer
Need to check if this is valid before doing anything
Extra NULL checks all around to prevent any invalid
lists from SurfaceFlinger
Change-Id: I57ca97167e469910bcaaa68672ae70b41a061ded
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 8514d32..1b5b609 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -125,15 +125,20 @@
for (uint32_t i = 0; i < numDisplays; i++) {
hwc_display_contents_1_t *list = displays[i];
- switch(i) {
- case HWC_DISPLAY_PRIMARY:
- ret = hwc_prepare_primary(dev, list);
- break;
- case HWC_DISPLAY_EXTERNAL:
- ret = hwc_prepare_external(dev, list);
- break;
- default:
- ret = -EINVAL;
+ if(list && list->numHwLayers) {
+ uint32_t last = list->numHwLayers - 1;
+ if(list->hwLayers[last].handle != NULL) {
+ switch(i) {
+ case HWC_DISPLAY_PRIMARY:
+ ret = hwc_prepare_primary(dev, list);
+ break;
+ case HWC_DISPLAY_EXTERNAL:
+ ret = hwc_prepare_external(dev, list);
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ }
}
}
return ret;