Mesa (main): anv: fix potential integer overflow

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Oct 11 10:59:48 UTC 2021


Module: Mesa
Branch: main
Commit: 3b9b6db031bd6a4d7715a4a8cef47e0eb6318294
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3b9b6db031bd6a4d7715a4a8cef47e0eb6318294

Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date:   Mon Oct 11 10:58:11 2021 +0200

anv: fix potential integer overflow

Description by Coverity:
"Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << b with type int
(32 bits, signed) is evaluated using 32-bit arithmetic, and then used in
a context that expects an expression of type VkAccessFlags2KHR (64 bits,
unsigned)"

CID: 1492745
CID: 1492748

Fixes: b996fa8efaa ("anv: implement VK_KHR_synchronization2")
Signed-off-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13284>

---

 src/intel/vulkan/anv_private.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 41c8b0d9972..2ac3907627b 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2499,7 +2499,7 @@ anv_pipe_flush_bits_for_access_flags(struct anv_device *device,
    enum anv_pipe_bits pipe_bits = 0;
 
    u_foreach_bit64(b, flags) {
-      switch ((VkAccessFlags2KHR)(1 << b)) {
+      switch ((VkAccessFlags2KHR)BITFIELD64_BIT(b)) {
       case VK_ACCESS_2_SHADER_WRITE_BIT_KHR:
       case VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT_KHR:
          /* We're transitioning a buffer that was previously used as write
@@ -2576,7 +2576,7 @@ anv_pipe_invalidate_bits_for_access_flags(struct anv_device *device,
    enum anv_pipe_bits pipe_bits = 0;
 
    u_foreach_bit64(b, flags) {
-      switch ((VkAccessFlags2KHR)(1 << b)) {
+      switch ((VkAccessFlags2KHR)BITFIELD64_BIT(b)) {
       case VK_ACCESS_2_INDIRECT_COMMAND_READ_BIT_KHR:
          /* Indirect draw commands take a buffer as input that we're going to
           * read from the command streamer to load some of the HW registers



More information about the mesa-commit mailing list