Commit 8801c35c authored by Shuah Khan's avatar Shuah Khan Committed by Andrew Morton
Browse files

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: default avatarShuah Khan <skhan@linuxfoundation.org>
Reviewed-by: default avatarLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: default avatarLiam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 5d042707
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -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])