]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools: fix -Wunused-result in linux.c
authorShuah Khan <skhan@linuxfoundation.org>
Fri, 11 Oct 2024 22:51:55 +0000 (16:51 -0600)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 6 Nov 2024 01:12:32 +0000 (17:12 -0800)
Fix the following -Wunused-result warnings on posix_memalign()
return values and add error handling.

./shared/linux.c:100:25: warning: ignoring return value of `posix_memalign' declared with attribute `warn_unused_result' [-Wunused-result]
  100 |          posix_memalign(&p, cachep->align, cachep->size);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../shared/linux.c: In function `kmem_cache_alloc_bulk':
../shared/linux.c:198:33: warning: ignoring return value of `posix_memalign' declared with attribute `warn_unused_result' [-Wunused-result]
  198 |          posix_memalign(&p[i], cachep->align,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  199 |                                cachep->size);
      |                                ~~~~~~~~~~~~~

Link: https://lkml.kernel.org/r/20241011225155.27607-1-skhan@linuxfoundation.org
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/shared/linux.c

index 17263696b5d88040f2901cf367c00677b5c59bfb..66dbb362385f3c3d923233448cc591adfe6dc9e7 100644 (file)
@@ -96,10 +96,13 @@ void *kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
                p = node;
        } else {
                pthread_mutex_unlock(&cachep->lock);
-               if (cachep->align)
-                       posix_memalign(&p, cachep->align, cachep->size);
-               else
+               if (cachep->align) {
+                       if (posix_memalign(&p, cachep->align, cachep->size) < 0)
+                               return NULL;
+               } else {
                        p = malloc(cachep->size);
+               }
+
                if (cachep->ctor)
                        cachep->ctor(p);
                else if (gfp & __GFP_ZERO)
@@ -195,8 +198,9 @@ int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size,
                        }
 
                        if (cachep->align) {
-                               posix_memalign(&p[i], cachep->align,
-                                              cachep->size);
+                               if (posix_memalign(&p[i], cachep->align,
+                                              cachep->size) < 0)
+                                       break;
                        } else {
                                p[i] = malloc(cachep->size);
                                if (!p[i])