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

Author: Kai Wasserbäch <[email protected]>
Date:   Fri Oct 13 14:04:37 2023 +0200

fix: clover: warning: ignoring return value of ‘int posix_memalign(…)’ 
[-Wunused-result]

During builds GCC 13.2 issues the following warning:
src/gallium/frontends/clover/api/memory.cpp:612:21: warning: ignoring return 
value of ‘int posix_memalign(void**, size_t, size_t)’ declared with attribute 
‘warn_unused_result’ [-Wunused-result]
  612 |       posix_memalign(&ptr, alignment, size);
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

Fix this by checking the returned value is actually 0 and if not we now
report a nullptr.

Signed-off-by: Kai Wasserbäch <[email protected]>
Reviewed-by: Karol Herbst <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25724>

---

 src/gallium/frontends/clover/api/memory.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/gallium/frontends/clover/api/memory.cpp 
b/src/gallium/frontends/clover/api/memory.cpp
index 062fbb98c5b..ea553efe1f4 100644
--- a/src/gallium/frontends/clover/api/memory.cpp
+++ b/src/gallium/frontends/clover/api/memory.cpp
@@ -609,7 +609,9 @@ clSVMAlloc(cl_context d_ctx,
       void *ptr = nullptr;
       if (alignment < sizeof(void*))
          alignment = sizeof(void*);
-      posix_memalign(&ptr, alignment, size);
+      int ret = posix_memalign(&ptr, alignment, size);
+      if (ret)
+         return nullptr;
 
       if (ptr)
          ctx.add_svm_allocation(ptr, size);

Reply via email to