drm_hwcomposer: Validate gralloc0 name for minigbm and libdrm getters
Using of incorrect gralloc0 results in a runtime issues, with logs like
"Cannot convert hal format to drm format <VALUE>" or other.
Validate gralloc name and exit gracefully in case it doesnt't match the one
we are expecting.
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.cpp b/bufferinfo/legacy/BufferInfoMinigbm.cpp
index 1657ea6..93b9e98 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.cpp
+++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp
@@ -22,6 +22,7 @@
#include <xf86drmMode.h>
#include <cerrno>
+#include <cstring>
#include "cros_gralloc_handle.h"
#include "utils/log.h"
@@ -57,4 +58,16 @@
return 0;
}
+constexpr char cros_gralloc_module_name[] = "CrOS Gralloc";
+
+int BufferInfoMinigbm::ValidateGralloc() {
+ if (strcmp(gralloc_->common.name, cros_gralloc_module_name) != 0) {
+ ALOGE("Gralloc name isn't valid: Expected: \"%s\", Actual: \"%s\"",
+ cros_gralloc_module_name, gralloc_->common.name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
} // namespace android