Subject: Re: [PATCH bpf-next v1 1/1] bpf: Annotate rqspinlock lock acquiring functions with __must_check

From: David Laight <[email-masked]>
Date: Thu, 20 Nov 2025 21:27:13 +0000

On Thu, 20 Nov 2025 12:12:12 -0800
Amery Hung <[email-masked]> wrote:

> On Tue, Nov 18, 2025 at 2:42 AM David Laight
> <[email-masked]> wrote:
> >
> > On Tue, 18 Nov 2025 05:16:50 -0500
> > Kumar Kartikeya Dwivedi <[email-masked]> wrote:
> >  
> > > On Mon, 17 Nov 2025 at 14:15, Amery Hung <[email-masked]> wrote:  
> > > >
> > > > Locking a resilient queued spinlock can fail when deadlock or timeout
> > > > happen. Mark the lock acquring functions with __must_check to make sure
> > > > callers always handle the returned error.
> > > >
> > > > Suggested-by: Andrii Nakryiko <[email-masked]>
> > > > Signed-off-by: Amery Hung <[email-masked]>
> > > > ---  
> > >
> > > Looks like it's working :)
> > > I would just explicitly ignore with (void) cast the locktorture case.  
> >
> > I'm not sure that works - I usually have to try a lot harder to ignore
> > a '__must_check' result.  
> 
> Thanks for the heads up.
> 
> Indeed, gcc still complains about it even casting the return to (void)
> while clang does not.
> 
> I have to silence the warning by:
> 
> #pragma GCC diagnostic push
> #pragma GCC diagnostic ignored "-Wunused-result"
>        raw_res_spin_lock(&rqspinlock);
> #pragma GCC diagnostic pop

I think the simpler:
	if (raw_res_spin_lock(&rqspinlock)) {};
also works.
But I'm sure I've resorted to crap like:
	x += foo() ? 0 : 0;
and/or:
	x += foo() == IMPOSSIBLE_VALUE;
and/or wrapping the call in a static inline function.

It is all a right PITA when you are doing read/write on a pipe
that is being used for events.

At least no one has put a 'must_check' on fprintf() (yet).
Code that looks at the return value is usually broken!
(hint: you need to call fflush() and then check ferror().)

	David

> Thanks!
> Amery
> >         David