fix: clover: warning: ignoring return value of ‘int posix_memalign(…)’ [-Wunused...
authorKai Wasserbäch <kai@dev.carbon-project.org>
Fri, 13 Oct 2023 12:04:37 +0000 (14:04 +0200)
committerMarge Bot <emma+marge@anholt.net>
Sat, 14 Oct 2023 17:12:37 +0000 (17:12 +0000)
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 <kai@dev.carbon-project.org>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25724>

src/gallium/frontends/clover/api/memory.cpp

index 062fbb98c5bf48f60b6a9abbf5e5c20a6be7ac81..ea553efe1f413df56ca7fe1a6fa880b0d067d4fb 100644 (file)
@@ -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);