sdm: fix null pointer dereference and vector initialization.
Change-Id: I25bb8daa6b49223a443a31d1ae17560ed6fca486
Signed-off-by: Pramodh Kumar Mukunda <pkmuku@codeaurora.org>
diff --git a/libgralloc1/gr_utils.cpp b/libgralloc1/gr_utils.cpp
index b3056e1..560bb08 100644
--- a/libgralloc1/gr_utils.cpp
+++ b/libgralloc1/gr_utils.cpp
@@ -509,7 +509,9 @@
// Query GPU for UBWC only if buffer is intended to be used by GPU.
if ((cons_usage & GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE) ||
(prod_usage & GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET)) {
- enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format);
+ if (AdrenoMemInfo::GetInstance()) {
+ enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format);
+ }
}
// Allow UBWC, only if CPU usage flags are not set
@@ -675,8 +677,10 @@
int tile = ubwc_enabled;
if (IsUncompressedRGBFormat(format)) {
- AdrenoMemInfo::GetInstance()->AlignUnCompressedRGB(width, height, format, tile, alignedw,
- alignedh);
+ if (AdrenoMemInfo::GetInstance()) {
+ AdrenoMemInfo::GetInstance()->AlignUnCompressedRGB(width, height, format, tile, alignedw,
+ alignedh);
+ }
return;
}
@@ -686,7 +690,9 @@
}
if (IsCompressedRGBFormat(format)) {
- AdrenoMemInfo::GetInstance()->AlignCompressedRGB(width, height, format, alignedw, alignedh);
+ if (AdrenoMemInfo::GetInstance()) {
+ AdrenoMemInfo::GetInstance()->AlignCompressedRGB(width, height, format, alignedw, alignedh);
+ }
return;
}
@@ -698,6 +704,9 @@
switch (format) {
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ if (AdrenoMemInfo::GetInstance() == nullptr) {
+ return;
+ }
alignment = AdrenoMemInfo::GetInstance()->GetGpuPixelAlignment();
aligned_w = ALIGN(width, alignment);
break;
diff --git a/sdm/libs/hwc2/hwc_buffer_allocator.cpp b/sdm/libs/hwc2/hwc_buffer_allocator.cpp
index a1b763c..0e05ca9 100644
--- a/sdm/libs/hwc2/hwc_buffer_allocator.cpp
+++ b/sdm/libs/hwc2/hwc_buffer_allocator.cpp
@@ -48,12 +48,14 @@
} else {
gralloc1_open(module_, &gralloc_device_);
}
- ReleaseBuffer_ = reinterpret_cast<GRALLOC1_PFN_RELEASE>(
- gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_RELEASE));
- Perform_ = reinterpret_cast<GRALLOC1_PFN_PERFORM>(
- gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_PERFORM));
- Lock_ = reinterpret_cast<GRALLOC1_PFN_LOCK>(
- gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_LOCK));
+ if (gralloc_device_ != nullptr) {
+ ReleaseBuffer_ = reinterpret_cast<GRALLOC1_PFN_RELEASE>(
+ gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_RELEASE));
+ Perform_ = reinterpret_cast<GRALLOC1_PFN_PERFORM>(
+ gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_PERFORM));
+ Lock_ = reinterpret_cast<GRALLOC1_PFN_LOCK>(
+ gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_LOCK));
+ }
}
HWCBufferAllocator::~HWCBufferAllocator() {