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/BufferInfoGetter.h b/bufferinfo/BufferInfoGetter.h
index 60ca985..7b088df 100644
--- a/bufferinfo/BufferInfoGetter.h
+++ b/bufferinfo/BufferInfoGetter.h
@@ -49,6 +49,10 @@
int Init();
+ virtual int ValidateGralloc() {
+ return 0;
+ }
+
int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override = 0;
static std::unique_ptr<LegacyBufferInfoGetter> CreateInstance();
@@ -65,9 +69,13 @@
LegacyBufferInfoGetter::CreateInstance() { \
auto instance = std::make_unique<getter_>(); \
if (instance) { \
- int ret = instance->Init(); \
- if (ret) { \
- ALOGE("Failed to initialize the " #getter_ " getter %d", ret); \
+ int err = instance->Init(); \
+ if (err) { \
+ ALOGE("Failed to initialize the " #getter_ " getter %d", err); \
+ instance.reset(); \
+ } \
+ err = instance->ValidateGralloc(); \
+ if (err) { \
instance.reset(); \
} \
} \
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp
index 6243d8d..e70536b 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.cpp
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -204,4 +204,20 @@
return 0;
}
+constexpr char gbm_gralloc_module_name[] = "GBM Memory Allocator";
+constexpr char drm_gralloc_module_name[] = "DRM Memory Allocator";
+
+int BufferInfoLibdrm::ValidateGralloc() {
+ if (strcmp(gralloc_->common.name, drm_gralloc_module_name) != 0 &&
+ strcmp(gralloc_->common.name, gbm_gralloc_module_name) != 0) {
+ ALOGE(
+ "Gralloc name isn't valid: Expected: \"%s\" or \"%s\", Actual: \"%s\"",
+ gbm_gralloc_module_name, drm_gralloc_module_name,
+ gralloc_->common.name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.h b/bufferinfo/legacy/BufferInfoLibdrm.h
index 4d37d00..cad8add 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.h
+++ b/bufferinfo/legacy/BufferInfoLibdrm.h
@@ -27,6 +27,7 @@
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ int ValidateGralloc() override;
private:
bool GetYuvPlaneInfo(int num_fds, buffer_handle_t handle, hwc_drm_bo_t *bo);
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
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.h b/bufferinfo/legacy/BufferInfoMinigbm.h
index bff9d74..04cc2ae 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.h
+++ b/bufferinfo/legacy/BufferInfoMinigbm.h
@@ -27,6 +27,7 @@
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ int ValidateGralloc() override;
};
} // namespace android