lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <19434478-b8e5-4158-9d8d-36e8db1563bc@lucifer.local>
Date: Mon, 14 Oct 2024 12:30:36 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Shuah Khan <skhan@...uxfoundation.org>
Cc: Liam.Howlett@...cle.com, akpm@...ux-foundation.org, vbabka@...e.cz,
        sidhartha.kumar@...cle.com, zhangpeng.00@...edance.com,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] tools: fix -Wunused-result in linux.c

On Fri, Oct 11, 2024 at 04:51:55PM -0600, Shuah Khan wrote:
> 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);
>       |                                ~~~~~~~~~~~~~
>
> Signed-off-by: Shuah Khan <skhan@...uxfoundation.org>

Looks good to me!

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>

> ---
>  tools/testing/shared/linux.c | 14 +++++++++-----
>  1 file 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])
> --
> 2.40.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ