From 927729d9ea68ff83e3bbdf9607a2ac0f23a5743a Mon Sep 17 00:00:00 2001 From: Pramodh Kumar Mukunda Date: Thu, 15 Jun 2017 16:18:51 +0530 Subject: [PATCH] sdm: fix null pointer dereference and vector initialization. Change-Id: I25bb8daa6b49223a443a31d1ae17560ed6fca486 Signed-off-by: Pramodh Kumar Mukunda --- libgralloc1/gr_utils.cpp | 17 +++++++++++++---- sdm/libs/hwc2/hwc_buffer_allocator.cpp | 14 ++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/libgralloc1/gr_utils.cpp b/libgralloc1/gr_utils.cpp index b3056e11..560bb08c 100644 --- a/libgralloc1/gr_utils.cpp +++ b/libgralloc1/gr_utils.cpp @@ -509,7 +509,9 @@ bool IsUBwcEnabled(int format, gralloc1_producer_usage_t prod_usage, // 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 @@ void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw, 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 @@ void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw, } 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 @@ void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw, 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 a1b763ca..0e05ca9d 100644 --- a/sdm/libs/hwc2/hwc_buffer_allocator.cpp +++ b/sdm/libs/hwc2/hwc_buffer_allocator.cpp @@ -48,12 +48,14 @@ HWCBufferAllocator::HWCBufferAllocator() { } else { gralloc1_open(module_, &gralloc_device_); } - ReleaseBuffer_ = reinterpret_cast( - gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_RELEASE)); - Perform_ = reinterpret_cast( - gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_PERFORM)); - Lock_ = reinterpret_cast( - gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_LOCK)); + if (gralloc_device_ != nullptr) { + ReleaseBuffer_ = reinterpret_cast( + gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_RELEASE)); + Perform_ = reinterpret_cast( + gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_PERFORM)); + Lock_ = reinterpret_cast( + gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_LOCK)); + } } HWCBufferAllocator::~HWCBufferAllocator() {