diff options
author | Shuah Khan <skhan@linuxfoundation.org> | 2024-10-11 16:51:55 -0600 |
---|---|---|
committer | Andrew Morton <akpm@linux-foundation.org> | 2024-11-05 17:12:32 -0800 |
commit | 8801c35c3672c8492824f5d3c4d3b37f43ed63c3 (patch) | |
tree | b98b69b1b2a9ec08d186d46411b9cf0917639a43 /tools/testing/shared | |
parent | 5d042707089f0d0c49473d05250e4f319a71e1df (diff) |
tools: fix -Wunused-result in linux.c
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>
Diffstat (limited to 'tools/testing/shared')
-rw-r--r-- | tools/testing/shared/linux.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/testing/shared/linux.c b/tools/testing/shared/linux.c index 17263696b5d8..66dbb362385f 100644 --- a/tools/testing/shared/linux.c +++ b/tools/testing/shared/linux.c @@ -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]) |