The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: "'Liam R. Howlett'" <Liam.Howlett@oracle.com>,
	Shuah Khan <skhan@linuxfoundation.org>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"vbabka@suse.cz" <vbabka@suse.cz>,
	"sidhartha.kumar@oracle.com" <sidhartha.kumar@oracle.com>,
	"lorenzo.stoakes@oracle.com" <lorenzo.stoakes@oracle.com>,
	"zhangpeng.00@bytedance.com" <zhangpeng.00@bytedance.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] tools: fix -Wunused-result in linux.c
Date: Mon, 21 Oct 2024 16:10:18 +0000	[thread overview]
Message-ID: <13ddebb3e15b4a94b466c6ee5f3f2f42@AcuMS.aculab.com> (raw)
In-Reply-To: <ddepbtajvjqoftjqanab7dpcx62pjrl4s3cowhciocevfa43wa@sncxpv75hpjp>

From: Liam R. Howlett
> Sent: 15 October 2024 02:11
> 
> * Shuah Khan <skhan@linuxfoundation.org> [241011 18:52]:
> > 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@linuxfoundation.org>
> 
> Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.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);
> > +		}
> > +

You really ought to be checking malloc() as well.
Perhaps:
		if (...) {
			if (posix_memalign(...) < 0)
				p = NULL;
		} else {
			p = malloc(...);
		}
		if (!p)
			return NULL;

Or just use a hack to get the compiler to STFU :-)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2024-10-21 16:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 22:51 [PATCH] tools: fix -Wunused-result in linux.c Shuah Khan
2024-10-14 11:30 ` Lorenzo Stoakes
2024-10-15  1:11 ` Liam R. Howlett
2024-10-21 16:10   ` David Laight [this message]
2024-10-21 16:32     ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13ddebb3e15b4a94b466c6ee5f3f2f42@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=sidhartha.kumar@oracle.com \
    --cc=skhan@linuxfoundation.org \
    --cc=vbabka@suse.cz \
    --cc=zhangpeng.00@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox