drm_hwcomposer: CI: Bump-up clang toolchain to v15

Address new clang-tidy findings, in most cases 'misc-const-correctness'
check was addressed by adding 'const' modifier, or in some cases changed
to 'auto' (where it's better for formatting).

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/.ci/.gitlab-ci-checkcommit.sh b/.ci/.gitlab-ci-checkcommit.sh
index c6f7c4e..ff293a8 100755
--- a/.ci/.gitlab-ci-checkcommit.sh
+++ b/.ci/.gitlab-ci-checkcommit.sh
@@ -50,7 +50,7 @@
 		exit 1
 	fi
 
-	git show "$h" -- | clang-format-diff-14 -p 1 -style=file > /tmp/format-fixup.patch
+	git show "$h" -- | clang-format-diff-15 -p 1 -style=file > /tmp/format-fixup.patch
 	if [ -s  /tmp/format-fixup.patch ]; then
 		cat /tmp/format-fixup.patch >&2
 		exit 1
diff --git a/.ci/Makefile b/.ci/Makefile
index 581c6d9..88cde2e 100644
--- a/.ci/Makefile
+++ b/.ci/Makefile
@@ -2,8 +2,8 @@
 INCLUDE_DIRS := . ../libdrm/include/drm include ./.ci/android_headers ./tests/test_include
 SYSTEM_INCLUDE_DIRS := /usr/include/libdrm
 
-CLANG := clang++-14
-CLANG_TIDY := clang-tidy-14
+CLANG := clang++-15
+CLANG_TIDY := clang-tidy-15
 OUT_DIR := /tmp/drm_hwcomposer/build
 SRC_DIR := .
 
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index eb0c265..f7f9caa 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,11 +1,11 @@
-image: ubuntu:22.04
+image: ubuntu:22.10
 
 variables:
   DEBIAN_FRONTEND: noninteractive
 
 before_script:
   - apt-get --quiet update --yes >/dev/null
-  - apt-get --quiet install --yes clang-14 clang-tidy-14 clang-format-14 git libdrm-dev blueprint-tools libgtest-dev make >/dev/null
+  - apt-get --quiet install --yes clang-15 clang-tidy-15 clang-format-15 git libdrm-dev blueprint-tools libgtest-dev make >/dev/null
 
 stages:
   - build
diff --git a/README.md b/README.md
index e98b5ae..5724b36 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
   you with formatting of your patches:
 
     ```
-    git diff | clang-format-diff-14 -p 1 -style=file
+    git diff | clang-format-diff-15 -p 1 -style=file
     ```
 
 * Hardware specific changes should be tested on relevant platforms before
diff --git a/backend/Backend.cpp b/backend/Backend.cpp
index ba0518a..679f083 100644
--- a/backend/Backend.cpp
+++ b/backend/Backend.cpp
@@ -43,7 +43,7 @@
 
     MarkValidated(layers, client_start, client_size);
 
-    bool testing_needed = !(client_start == 0 && client_size == layers.size());
+    auto testing_needed = client_start != 0 || client_size != layers.size();
 
     AtomicCommitArgs a_args = {.test_only = true};
 
@@ -99,7 +99,7 @@
   uint32_t pixops = 0;
   for (size_t z_order = 0; z_order < layers.size(); ++z_order) {
     if (z_order >= first_z && z_order < first_z + size) {
-      hwc_rect_t &df = layers[z_order]->GetLayerData().pi.display_frame;
+      auto &df = layers[z_order]->GetLayerData().pi.display_frame;
       pixops += (df.right - df.left) * (df.bottom - df.top);
     }
   }
@@ -129,16 +129,16 @@
   if (avail_planes < display->layers().size())
     avail_planes--;
 
-  int extra_client = int(layers.size() - client_size) - int(avail_planes);
+  const int extra_client = int(layers.size() - client_size) - int(avail_planes);
 
   if (extra_client > 0) {
     int start = 0;
     size_t steps = 0;
     if (client_size != 0) {
-      int prepend = std::min(client_start, extra_client);
-      int append = std::min(int(layers.size()) -
-                                int(client_start + client_size),
-                            extra_client);
+      const int prepend = std::min(client_start, extra_client);
+      const int append = std::min(int(layers.size()) -
+                                      int(client_start + client_size),
+                                  extra_client);
       start = client_start - (int)prepend;
       client_size += extra_client;
       steps = 1 + std::min(std::min(append, prepend),
@@ -150,7 +150,7 @@
 
     uint32_t gpu_pixops = UINT32_MAX;
     for (size_t i = 0; i < steps; i++) {
-      uint32_t po = CalcPixOps(layers, start + i, client_size);
+      const uint32_t po = CalcPixOps(layers, start + i, client_size);
       if (po < gpu_pixops) {
         gpu_pixops = po;
         client_start = start + int(i);
diff --git a/backend/BackendManager.cpp b/backend/BackendManager.cpp
index 9bf6324..c1bc0f6 100644
--- a/backend/BackendManager.cpp
+++ b/backend/BackendManager.cpp
@@ -42,7 +42,7 @@
 }
 
 int BackendManager::SetBackendForDisplay(HwcDisplay *display) {
-  std::string driver_name(display->GetPipe().device->GetName());
+  auto driver_name(display->GetPipe().device->GetName());
   char backend_override[PROPERTY_VALUE_MAX];
   property_get("vendor.hwc.backend_override", backend_override,
                driver_name.c_str());
diff --git a/bufferinfo/BufferInfoGetter.cpp b/bufferinfo/BufferInfoGetter.cpp
index 95c1a23..5716176 100644
--- a/bufferinfo/BufferInfoGetter.cpp
+++ b/bufferinfo/BufferInfoGetter.cpp
@@ -68,7 +68,7 @@
 }
 
 int LegacyBufferInfoGetter::Init() {
-  int ret = hw_get_module(
+  const int ret = hw_get_module(
       GRALLOC_HARDWARE_MODULE_ID,
       // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
       reinterpret_cast<const hw_module_t **>(&gralloc_));
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp
index ac71ec0..b314bdc 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.cpp
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -154,7 +154,7 @@
   if (num_fds == 1) {
     bo->prime_fds[2] = bo->prime_fds[1] = bo->prime_fds[0];
   } else {
-    int expected_planes = (ycbcr.chroma_step == 2) ? 2 : 3;
+    const int expected_planes = (ycbcr.chroma_step == 2) ? 2 : 3;
     if (num_fds != expected_planes)
       return false;
   }
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.cpp b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
index 1c7f4d0..461e2eb 100644
--- a/bufferinfo/legacy/BufferInfoMaliHisi.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
@@ -77,7 +77,7 @@
   if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
     return {};
 
-  uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
+  const uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
   if (fmt == DRM_FORMAT_INVALID)
     return {};
 
@@ -100,10 +100,10 @@
       if (hnd->usage &
           (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK))
         align = 16;
-      int adjusted_height = MALI_ALIGN(hnd->height, 2);
-      int y_size = adjusted_height * hnd->byte_stride;
-      int vu_stride = MALI_ALIGN(hnd->byte_stride / 2, align);
-      int v_size = vu_stride * (adjusted_height / 2);
+      const int adjusted_height = MALI_ALIGN(hnd->height, 2);
+      const int y_size = adjusted_height * hnd->byte_stride;
+      const int vu_stride = MALI_ALIGN(hnd->byte_stride / 2, align);
+      const int v_size = vu_stride * (adjusted_height / 2);
 
       /* V plane*/
       bi.prime_fds[1] = hnd->share_fd;
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
index 2e10460..6dac973 100644
--- a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
@@ -38,7 +38,7 @@
   if (!hnd)
     return {};
 
-  uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
+  const uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
   if (fmt == DRM_FORMAT_INVALID)
     return {};
 
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.cpp b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
index 8160296..536e5a6 100644
--- a/bufferinfo/legacy/BufferInfoMaliMeson.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
@@ -70,7 +70,7 @@
   if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
     return {};
 
-  uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
+  const uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
   if (fmt == DRM_FORMAT_INVALID)
     return {};
 
diff --git a/compositor/LayerData.h b/compositor/LayerData.h
index d04514d..92d4da0 100644
--- a/compositor/LayerData.h
+++ b/compositor/LayerData.h
@@ -49,14 +49,14 @@
   hwc_rect_t display_frame{};
 
   bool RequireScalingOrPhasing() const {
-    float src_width = source_crop.right - source_crop.left;
-    float src_height = source_crop.bottom - source_crop.top;
+    const float src_width = source_crop.right - source_crop.left;
+    const float src_height = source_crop.bottom - source_crop.top;
 
     auto dest_width = float(display_frame.right - display_frame.left);
     auto dest_height = float(display_frame.bottom - display_frame.top);
 
-    bool scaling = src_width != dest_width || src_height != dest_height;
-    bool phasing = (source_crop.left - std::floor(source_crop.left) != 0) ||
+    auto scaling = src_width != dest_width || src_height != dest_height;
+    auto phasing = (source_crop.left - std::floor(source_crop.left) != 0) ||
                    (source_crop.top - std::floor(source_crop.top) != 0);
     return scaling || phasing;
   }
diff --git a/drm/DrmAtomicStateManager.cpp b/drm/DrmAtomicStateManager.cpp
index 5d2eebd..3582b82 100644
--- a/drm/DrmAtomicStateManager.cpp
+++ b/drm/DrmAtomicStateManager.cpp
@@ -44,6 +44,7 @@
 
 // NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme
 auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
+  // NOLINTNEXTLINE(misc-const-correctness)
   ATRACE_CALL();
 
   if (args.active && *args.active == active_frame_state_.crtc_active_state) {
@@ -141,10 +142,11 @@
   }
 
   if (last_present_fence_) {
+    // NOLINTNEXTLINE(misc-const-correctness)
     ATRACE_NAME("WaitPriorFramePresented");
 
     constexpr int kTimeoutMs = 500;
-    int err = sync_wait(last_present_fence_.Get(), kTimeoutMs);
+    const int err = sync_wait(last_present_fence_.Get(), kTimeoutMs);
     if (err != 0) {
       ALOGE("sync_wait(fd=%i) returned: %i (errno: %i)",
             last_present_fence_.Get(), err, errno);
@@ -157,7 +159,7 @@
     flags |= DRM_MODE_ATOMIC_NONBLOCK;
   }
 
-  int err = drmModeAtomicCommit(drm->GetFd(), pset.get(), flags, drm);
+  auto err = drmModeAtomicCommit(drm->GetFd(), pset.get(), flags, drm);
 
   if (err != 0) {
     ALOGE("Failed to commit pset ret=%d\n", err);
@@ -223,9 +225,10 @@
     }
 
     {
+      // NOLINTNEXTLINE(misc-const-correctness)
       ATRACE_NAME("AsyncWaitForBuffersSwap");
       constexpr int kTimeoutMs = 500;
-      int err = sync_wait(present_fence.Get(), kTimeoutMs);
+      auto err = sync_wait(present_fence.Get(), kTimeoutMs);
       if (err != 0) {
         ALOGE("sync_wait(fd=%i) returned: %i (errno: %i)", present_fence.Get(),
               err, errno);
@@ -233,7 +236,7 @@
     }
 
     {
-      std::unique_lock lk(*mutex_);
+      const std::unique_lock lk(*mutex_);
       if (st_man_ == nullptr) {
         break;
       }
@@ -250,6 +253,7 @@
   assert(frames_staged_ - frames_tracked_ == 1);
   assert(last_present_fence_);
 
+  // NOLINTNEXTLINE(misc-const-correctness)
   ATRACE_NAME("CleanupPriorFrameResources");
   frames_tracked_++;
   active_frame_state_ = std::move(staged_frame_state_);
@@ -257,7 +261,7 @@
 }
 
 auto DrmAtomicStateManager::ExecuteAtomicCommit(AtomicCommitArgs &args) -> int {
-  int err = CommitFrame(args);
+  auto err = CommitFrame(args);
 
   if (!args.test_only) {
     if (err != 0) {
diff --git a/drm/DrmConnector.cpp b/drm/DrmConnector.cpp
index 4737316..69d029d 100644
--- a/drm/DrmConnector.cpp
+++ b/drm/DrmConnector.cpp
@@ -177,7 +177,7 @@
     }
 
     if (!exists) {
-      modes_.emplace_back(DrmMode(&connector_->modes[i]));
+      modes_.emplace_back(&connector_->modes[i]);
     }
   }
 
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index 0f73f1f..33adf2a 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -161,7 +161,7 @@
   // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
   create_blob.data = (__u64)data;
 
-  int ret = drmIoctl(GetFd(), DRM_IOCTL_MODE_CREATEPROPBLOB, &create_blob);
+  auto ret = drmIoctl(GetFd(), DRM_IOCTL_MODE_CREATEPROPBLOB, &create_blob);
   if (ret != 0) {
     ALOGE("Failed to create mode property blob %d", ret);
     return {};
@@ -171,8 +171,8 @@
       new uint32_t(create_blob.blob_id), [this](const uint32_t *it) {
         struct drm_mode_destroy_blob destroy_blob {};
         destroy_blob.blob_id = (__u32)*it;
-        int err = drmIoctl(GetFd(), DRM_IOCTL_MODE_DESTROYPROPBLOB,
-                           &destroy_blob);
+        auto err = drmIoctl(GetFd(), DRM_IOCTL_MODE_DESTROYPROPBLOB,
+                            &destroy_blob);
         if (err != 0) {
           ALOGE("Failed to destroy mode property blob %" PRIu32 "/%d", *it,
                 err);
@@ -231,7 +231,7 @@
     return false;
   }
 
-  bool is_kms = res->count_crtcs > 0 && res->count_connectors > 0 &&
+  auto is_kms = res->count_crtcs > 0 && res->count_connectors > 0 &&
                 res->count_encoders > 0;
 
   return is_kms;
diff --git a/drm/DrmDisplayPipeline.cpp b/drm/DrmDisplayPipeline.cpp
index e81544d..7973529 100644
--- a/drm/DrmDisplayPipeline.cpp
+++ b/drm/DrmDisplayPipeline.cpp
@@ -171,9 +171,9 @@
   std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> planes;
   planes.emplace_back(primary_plane);
 
-  static bool use_overlay_planes = ReadUseOverlayProperty();
+  const static bool kUseOverlayPlanes = ReadUseOverlayProperty();
 
-  if (use_overlay_planes) {
+  if (kUseOverlayPlanes) {
     for (const auto &plane : device->GetPlanes()) {
       if (plane->IsCrtcSupported(*crtc->Get())) {
         if (plane->GetType() == DRM_PLANE_TYPE_OVERLAY) {
diff --git a/drm/DrmFbImporter.cpp b/drm/DrmFbImporter.cpp
index 585b789..f0be32f 100644
--- a/drm/DrmFbImporter.cpp
+++ b/drm/DrmFbImporter.cpp
@@ -37,6 +37,7 @@
 auto DrmFbIdHandle::CreateInstance(BufferInfo *bo, GemHandle first_gem_handle,
                                    DrmDevice &drm)
     -> std::shared_ptr<DrmFbIdHandle> {
+  // NOLINTNEXTLINE(misc-const-correctness)
   ATRACE_NAME("Import dmabufs and register FB");
 
   // NOLINTNEXTLINE(cppcoreguidelines-owning-memory): priv. constructor usage
@@ -61,7 +62,7 @@
     }
   }
 
-  bool has_modifiers = bo->modifiers[0] != DRM_FORMAT_MOD_NONE &&
+  auto has_modifiers = bo->modifiers[0] != DRM_FORMAT_MOD_NONE &&
                        bo->modifiers[0] != DRM_FORMAT_MOD_INVALID;
 
   if (!drm.HasAddFb2ModifiersSupport() && has_modifiers) {
@@ -92,6 +93,7 @@
 }
 
 DrmFbIdHandle::~DrmFbIdHandle() {
+  // NOLINTNEXTLINE(misc-const-correctness)
   ATRACE_NAME("Close FB and dmabufs");
 
   /* Destroy framebuffer object */
@@ -116,7 +118,7 @@
       continue;
     }
     gem_close.handle = gem_handles_[i];
-    int32_t err = drmIoctl(drm_->GetFd(), DRM_IOCTL_GEM_CLOSE, &gem_close);
+    auto err = drmIoctl(drm_->GetFd(), DRM_IOCTL_GEM_CLOSE, &gem_close);
     if (err != 0) {
       ALOGE("Failed to close gem handle %d, errno: %d", gem_handles_[i], errno);
     }
@@ -127,8 +129,7 @@
     -> std::shared_ptr<DrmFbIdHandle> {
   /* Lookup DrmFbIdHandle in cache first. First handle serves as a cache key. */
   GemHandle first_handle = 0;
-  int32_t err = drmPrimeFDToHandle(drm_->GetFd(), bo->prime_fds[0],
-                                   &first_handle);
+  auto err = drmPrimeFDToHandle(drm_->GetFd(), bo->prime_fds[0], &first_handle);
 
   if (err != 0) {
     ALOGE("Failed to import prime fd %d ret=%d", bo->prime_fds[0], err);
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index 5051d35..76a2c6e 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -169,6 +169,11 @@
 }
 
 bool DrmPlane::IsValidForLayer(LayerData *layer) {
+  if (layer == nullptr || !layer->bi) {
+    ALOGE("%s: Invalid parameters", __func__);
+    return false;
+  }
+
   if (!rotation_property_) {
     if (layer->pi.transform != LayerTransform::kIdentity) {
       ALOGV("No rotation property on plane %d", GetId());
@@ -193,7 +198,7 @@
     return false;
   }
 
-  uint32_t format = layer->bi->format;
+  auto format = layer->bi->format;
   if (!IsFormatSupported(format)) {
     ALOGV("Plane %d does not supports %c%c%c%c format", GetId(), format,
           format >> 8, format >> 16, format >> 24);
@@ -241,8 +246,8 @@
 
 auto DrmPlane::AtomicSetState(drmModeAtomicReq &pset, LayerData &layer,
                               uint32_t zpos, uint32_t crtc_id) -> int {
-  if (!layer.fb) {
-    ALOGE("Expected a valid framebuffer for pset");
+  if (!layer.fb || !layer.bi) {
+    ALOGE("%s: Invalid arguments", __func__);
     return -EINVAL;
   }
 
@@ -317,8 +322,8 @@
 
 auto DrmPlane::GetPlaneProperty(const char *prop_name, DrmProperty &property,
                                 Presence presence) -> bool {
-  int err = drm_->GetProperty(GetId(), DRM_MODE_OBJECT_PLANE, prop_name,
-                              &property);
+  auto err = drm_->GetProperty(GetId(), DRM_MODE_OBJECT_PLANE, prop_name,
+                               &property);
   if (err != 0) {
     if (presence == Presence::kMandatory) {
       ALOGE("Could not get mandatory property \"%s\" from plane %d", prop_name,
diff --git a/drm/DrmProperty.cpp b/drm/DrmProperty.cpp
index 32f1c62..e0bf25e 100644
--- a/drm/DrmProperty.cpp
+++ b/drm/DrmProperty.cpp
@@ -50,7 +50,7 @@
     values_.emplace_back(p->values[i]);
 
   for (int i = 0; i < p->count_enums; ++i)
-    enums_.emplace_back(DrmPropertyEnum(&p->enums[i]));
+    enums_.emplace_back(&p->enums[i]);
 
   for (int i = 0; i < p->count_blobs; ++i)
     blob_ids_.emplace_back(p->blob_ids[i]);
diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp
index dbf0993..fb5c32b 100644
--- a/drm/ResourceManager.cpp
+++ b/drm/ResourceManager.cpp
@@ -54,8 +54,8 @@
   char path_pattern[PROPERTY_VALUE_MAX];
   // Could be a valid path or it can have at the end of it the wildcard %
   // which means that it will try open all devices until an error is met.
-  int path_len = property_get("vendor.hwc.drm.device", path_pattern,
-                              "/dev/dri/card%");
+  auto path_len = property_get("vendor.hwc.drm.device", path_pattern,
+                               "/dev/dri/card%");
   if (path_pattern[path_len - 1] != '%') {
     auto dev = DrmDevice::CreateInstance(path_pattern, this);
     if (dev) {
@@ -123,8 +123,8 @@
 
   for (auto *conn : ordered_connectors) {
     conn->UpdateModes();
-    bool connected = conn->IsConnected();
-    bool attached = attached_pipelines_.count(conn) != 0;
+    auto connected = conn->IsConnected();
+    auto attached = attached_pipelines_.count(conn) != 0;
 
     if (connected != attached) {
       ALOGI("%s connector %s", connected ? "Attaching" : "Detaching",
diff --git a/drm/UEventListener.cpp b/drm/UEventListener.cpp
index b56b8e1..79f23c4 100644
--- a/drm/UEventListener.cpp
+++ b/drm/UEventListener.cpp
@@ -47,8 +47,8 @@
     if (!hotplug_handler_ || !uevent_str)
       continue;
 
-    bool drm_event = uevent_str->find("DEVTYPE=drm_minor") != std::string::npos;
-    bool hotplug_event = uevent_str->find("HOTPLUG=1") != std::string::npos;
+    auto drm_event = uevent_str->find("DEVTYPE=drm_minor") != std::string::npos;
+    auto hotplug_event = uevent_str->find("HOTPLUG=1") != std::string::npos;
 
     if (drm_event && hotplug_event) {
       constexpr useconds_t kDelayAfterUeventUs = 200000;
diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp
index ed41189..7b4fae4 100644
--- a/drm/VSyncWorker.cpp
+++ b/drm/VSyncWorker.cpp
@@ -84,10 +84,10 @@
     refresh = pipe_->connector->Get()->GetActiveMode().v_refresh();
   }
 
-  int64_t phased_timestamp = GetPhasedVSync(kOneSecondNs /
-                                                static_cast<int>(refresh),
-                                            vsync.tv_sec * kOneSecondNs +
-                                                vsync.tv_nsec);
+  auto phased_timestamp = GetPhasedVSync(kOneSecondNs /
+                                             static_cast<int>(refresh),
+                                         vsync.tv_sec * kOneSecondNs +
+                                             vsync.tv_nsec);
   vsync.tv_sec = phased_timestamp / kOneSecondNs;
   vsync.tv_nsec = int(phased_timestamp - (vsync.tv_sec * kOneSecondNs));
   do {
@@ -120,8 +120,8 @@
   drmVBlank vblank{};
 
   if (pipe != nullptr) {
-    uint32_t high_crtc = (pipe->crtc->Get()->GetIndexInResArray()
-                          << DRM_VBLANK_HIGH_CRTC_SHIFT);
+    auto high_crtc = (pipe->crtc->Get()->GetIndexInResArray()
+                      << DRM_VBLANK_HIGH_CRTC_SHIFT);
 
     vblank.request.type = (drmVBlankSeqType)(DRM_VBLANK_RELATIVE |
                                              (high_crtc &
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index d968ab3..cecdbe5 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -31,7 +31,7 @@
 std::string HwcDisplay::DumpDelta(HwcDisplay::Stats delta) {
   if (delta.total_pixops_ == 0)
     return "No stats yet";
-  double ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_);
+  auto ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_);
 
   std::stringstream ss;
   ss << " Total frames count: " << delta.total_frames_ << "\n"
@@ -69,9 +69,9 @@
                              " VSync remains";
   }
 
-  std::string connector_name = IsInHeadlessMode()
-                                   ? "NULL-DISPLAY"
-                                   : GetPipe().connector->Get()->GetName();
+  auto connector_name = IsInHeadlessMode()
+                            ? std::string("NULL-DISPLAY")
+                            : GetPipe().connector->Get()->GetName();
 
   std::stringstream ss;
   ss << "- Display on: " << connector_name << "\n"
@@ -236,7 +236,7 @@
   }
 
   uint32_t num_changes = 0;
-  for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
+  for (auto &l : layers_) {
     if (l.second.IsTypeChanged()) {
       if (layers && num_changes < *num_elements)
         layers[num_changes] = l.first;
@@ -257,8 +257,8 @@
     return HWC2::Error::None;
   }
 
-  std::pair<uint32_t, uint32_t> min = pipeline_->device->GetMinResolution();
-  std::pair<uint32_t, uint32_t> max = pipeline_->device->GetMaxResolution();
+  auto min = pipeline_->device->GetMinResolution();
+  auto max = pipeline_->device->GetMaxResolution();
 
   if (width < min.first || height < min.second)
     return HWC2::Error::Unsupported;
@@ -296,8 +296,8 @@
   auto &hwc_config = configs_.hwc_configs[conf];
 
   static const int32_t kUmPerInch = 25400;
-  uint32_t mm_width = configs_.mm_width;
-  uint32_t mm_height = configs_.mm_height;
+  auto mm_width = configs_.mm_width;
+  auto mm_height = configs_.mm_height;
   auto attribute = static_cast<HWC2::Attribute>(attribute_in);
   switch (attribute) {
     case HWC2::Attribute::Width:
@@ -364,8 +364,8 @@
   } else {
     stream << "display-" << GetPipe().connector->Get()->GetId();
   }
-  std::string string = stream.str();
-  size_t length = string.length();
+  auto string = stream.str();
+  auto length = string.length();
   if (!name) {
     *size = length;
     return HWC2::Error::None;
@@ -450,7 +450,7 @@
     return HWC2::Error::None;
   }
 
-  int PrevModeVsyncPeriodNs = static_cast<int>(
+  auto PrevModeVsyncPeriodNs = static_cast<int>(
       1E9 / GetPipe().connector->Get()->GetActiveMode().v_refresh());
 
   auto mode_update_commited_ = false;
@@ -477,7 +477,7 @@
   for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
     switch (l.second.GetValidatedType()) {
       case HWC2::Composition::Device:
-        z_map.emplace(std::make_pair(l.second.GetZOrder(), &l.second));
+        z_map.emplace(l.second.GetZOrder(), &l.second);
         break;
       case HWC2::Composition::Client:
         // Place it at the z_order of the lowest client layer
@@ -489,7 +489,7 @@
     }
   }
   if (use_client_layer)
-    z_map.emplace(std::make_pair(client_z_order, &client_layer_));
+    z_map.emplace(client_z_order, &client_layer_);
 
   if (z_map.empty())
     return HWC2::Error::BadLayer;
@@ -530,7 +530,7 @@
 
   a_args.composition = current_plan_;
 
-  int ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
+  auto ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
 
   if (ret) {
     if (!a_args.test_only)
@@ -632,10 +632,15 @@
   }
 
   auto &bi = client_layer_.GetLayerData().bi;
-  hwc_frect_t source_crop = {.left = 0.0F,
-                             .top = 0.0F,
-                             .right = static_cast<float>(bi->width),
-                             .bottom = static_cast<float>(bi->height)};
+  if (!bi) {
+    ALOGE("%s: Invalid state", __func__);
+    return HWC2::Error::BadLayer;
+  }
+
+  auto source_crop = (hwc_frect_t){.left = 0.0F,
+                                   .top = 0.0F,
+                                   .right = static_cast<float>(bi->width),
+                                   .bottom = static_cast<float>(bi->height)};
   client_layer_.SetLayerSourceCrop(source_crop);
 
   return HWC2::Error::None;
@@ -709,7 +714,7 @@
                : HWC2::Error::BadParameter;
   };
 
-  int err = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
+  auto err = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
   if (err) {
     ALOGE("Failed to apply the dpms composition err=%d", err);
     return HWC2::Error::BadParameter;
@@ -940,7 +945,7 @@
 
 /* returns true if composition should be sent to client */
 bool HwcDisplay::ProcessClientFlatteningState(bool skip) {
-  int flattenning_state = flattenning_state_;
+  const int flattenning_state = flattenning_state_;
   if (flattenning_state == ClientFlattenningState::Disabled) {
     return false;
   }
diff --git a/hwc2_device/HwcDisplayConfigs.cpp b/hwc2_device/HwcDisplayConfigs.cpp
index 6a3ed5a..346572f 100644
--- a/hwc2_device/HwcDisplayConfigs.cpp
+++ b/hwc2_device/HwcDisplayConfigs.cpp
@@ -61,7 +61,7 @@
    * mode*/
   FillHeadless();
   /* Read real configs */
-  int ret = connector.UpdateModes();
+  auto ret = connector.UpdateModes();
   if (ret != 0) {
     ALOGE("Failed to update display modes %d", ret);
     return HWC2::Error::BadDisplay;
@@ -79,7 +79,7 @@
   preferred_config_id = 0;
   uint32_t preferred_config_group_id = 0;
 
-  uint32_t first_config_id = last_config_id;
+  auto first_config_id = last_config_id;
   uint32_t last_group_id = 1;
 
   /* Group modes */
@@ -143,7 +143,7 @@
       }
     }
 
-    bool has_both = has_interlaced && has_progressive;
+    auto has_both = has_interlaced && has_progressive;
     if (!has_both) {
       continue;
     }
@@ -159,7 +159,7 @@
         continue;
       }
 
-      bool disable = group_contains_preferred_interlaced
+      auto disable = group_contains_preferred_interlaced
                          ? !hwc_config.second.IsInterlaced()
                          : hwc_config.second.IsInterlaced();
 
diff --git a/hwc2_device/HwcLayer.cpp b/hwc2_device/HwcLayer.cpp
index c278732..589a0a7 100644
--- a/hwc2_device/HwcLayer.cpp
+++ b/hwc2_device/HwcLayer.cpp
@@ -205,6 +205,11 @@
 void HwcLayer::PopulateLayerData(bool test) {
   ImportFb();
 
+  if (!layer_data_.bi) {
+    ALOGE("%s: Invalid state", __func__);
+    return;
+  }
+
   if (blend_mode_ != BufferBlendMode::kUndefined) {
     layer_data_.bi->blend_mode = blend_mode_;
   }
@@ -227,7 +232,7 @@
     return false;
   }
 
-  int seq = swchain_lookup_table_[unique_id];
+  auto seq = swchain_lookup_table_[unique_id];
 
   if (swchain_cache_.count(seq) == 0) {
     return false;
@@ -274,7 +279,7 @@
       return;
     }
 
-    int seq = swchain_lookup_table_[unique_id];
+    auto seq = swchain_lookup_table_[unique_id];
 
     if (swchain_cache_.count(seq) == 0) {
       swchain_cache_[seq] = {};
diff --git a/hwc2_device/hwc2_device.cpp b/hwc2_device/hwc2_device.cpp
index a6dedb4..2242391 100644
--- a/hwc2_device/hwc2_device.cpp
+++ b/hwc2_device/hwc2_device.cpp
@@ -35,11 +35,11 @@
  * to the short "android::HwcLayer::SetLayerBuffer" for better logs readability
  */
 static std::string GetFuncName(const char *pretty_function) {
-  std::string str(pretty_function);
+  const std::string str(pretty_function);
   const char *start = "func = &";
-  size_t p1 = str.find(start);
+  auto p1 = str.find(start);
   p1 += strlen(start);
-  size_t p2 = str.find(',', p1);
+  auto p2 = str.find(',', p1);
   return str.substr(p1, p2 - p1);
 }
 
@@ -102,7 +102,7 @@
 static int HookDevClose(hw_device_t *dev) {
   // NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast): Safe
   auto *hwc2_dev = reinterpret_cast<hwc2_device_t *>(dev);
-  std::unique_ptr<DrmHwcTwo> ctx(ToDrmHwcTwo(hwc2_dev));
+  const std::unique_ptr<DrmHwcTwo> ctx(ToDrmHwcTwo(hwc2_dev));
   return 0;
 }
 
diff --git a/tests/worker_test.cpp b/tests/worker_test.cpp
index d1eb2b3..ac0c5fc 100644
--- a/tests/worker_test.cpp
+++ b/tests/worker_test.cpp
@@ -17,7 +17,7 @@
   void Routine() override {
     Lock();
     if (!enabled_) {
-      int ret = WaitForSignalOrExitLocked();
+      auto ret = WaitForSignalOrExitLocked();
       if (ret == -EINTR) {
         Unlock();
         return;
diff --git a/utils/UEvent.h b/utils/UEvent.h
index 17b3cab..64992a1 100644
--- a/utils/UEvent.h
+++ b/utils/UEvent.h
@@ -46,7 +46,7 @@
     addr.nl_groups = UINT32_MAX;
 
     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
-    int ret = bind(fd.Get(), (struct sockaddr *)&addr, sizeof(addr));
+    const int ret = bind(fd.Get(), (struct sockaddr *)&addr, sizeof(addr));
     if (ret != 0) {
       ALOGE("Failed to bind uevent socket: errno=%i", errno);
       return {};
diff --git a/utils/UniqueFd.h b/utils/UniqueFd.h
index d747a7f..f0855ba 100644
--- a/utils/UniqueFd.h
+++ b/utils/UniqueFd.h
@@ -21,6 +21,7 @@
 #include <unistd.h>
 
 #include <memory>
+#include <utility>
 
 namespace android {
 
diff --git a/utils/Worker.cpp b/utils/Worker.cpp
index d2b60c8..e1c7aee 100644
--- a/utils/Worker.cpp
+++ b/utils/Worker.cpp
@@ -30,7 +30,7 @@
 }
 
 int Worker::InitWorker() {
-  std::lock_guard<std::mutex> lk(mutex_);
+  const std::lock_guard<std::mutex> lk(mutex_);
   if (initialized())
     return -EALREADY;