Skip to content

Commit 8801c35

Browse files
shuahkhakpm00
authored andcommitted
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/[email protected] Signed-off-by: Shuah Khan <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Cc: Sidhartha Kumar <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5d04270 commit 8801c35

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/testing/shared/linux.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ void *kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
9696
p = node;
9797
} else {
9898
pthread_mutex_unlock(&cachep->lock);
99-
if (cachep->align)
100-
posix_memalign(&p, cachep->align, cachep->size);
101-
else
99+
if (cachep->align) {
100+
if (posix_memalign(&p, cachep->align, cachep->size) < 0)
101+
return NULL;
102+
} else {
102103
p = malloc(cachep->size);
104+
}
105+
103106
if (cachep->ctor)
104107
cachep->ctor(p);
105108
else if (gfp & __GFP_ZERO)
@@ -195,8 +198,9 @@ int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size,
195198
}
196199

197200
if (cachep->align) {
198-
posix_memalign(&p[i], cachep->align,
199-
cachep->size);
201+
if (posix_memalign(&p[i], cachep->align,
202+
cachep->size) < 0)
203+
break;
200204
} else {
201205
p[i] = malloc(cachep->size);
202206
if (!p[i])

0 commit comments

Comments
 (0)