Mesa (main): zink: fixup signedness of subtraction

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 16 15:36:05 UTC 2021


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

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Wed Jun 16 15:09:09 2021 +0200

zink: fixup signedness of subtraction

I'm not even going to pretend that I grok this code, but since we take
the abs value, it's pretty obvious that we meant to use a signed value
here. So let's cast the two operands to int before we subtract.

This was noticed by the following clang warning:

---8<---
../src/gallium/drivers/zink/zink_context.c:3284:14: warning: taking the
absolute value of unsigned type 'unsigned int' has no effect
[-Wabsolute-value]
      last = abs(reads - writes) > UINT32_MAX / 2 ? MIN2(reads, writes) : MAX2(reads, writes);
             ^
---8<---

Fixes: 0c1fe392e8d ("zink: implement a tc is_resource_busy hook")
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11421>

---

 src/gallium/drivers/zink/zink_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 785c80538c0..eb730f6c97f 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -3283,7 +3283,7 @@ zink_context_is_resource_busy(struct pipe_screen *pscreen, struct pipe_resource
    uint32_t last;
 
    if (reads && writes)
-      last = abs(reads - writes) > UINT32_MAX / 2 ? MIN2(reads, writes) : MAX2(reads, writes);
+      last = abs((int)reads - (int)writes) > UINT32_MAX / 2 ? MIN2(reads, writes) : MAX2(reads, writes);
    else
       last = reads ? reads : writes;
 



More information about the mesa-commit mailing list