Re: [RFC 0/2] refcount: attempt to avoid imbalance warnings

From: Bart Van Assche
Date: Fri Feb 07 2025 - 21:53:11 EST


On 6/30/22 9:34 AM, Linus Torvalds wrote:
On Thu, Jun 30, 2022 at 6:59 AM Alexander Aring <aahringo@xxxxxxxxxx> wrote:

I send this patch series as RFC because it was necessary to do a kref
change after adding __cond_lock() to refcount_dec_and_lock()
functionality.

Can you try something like this instead?

This is two separate patches - one for sparse, and one for the kernel.

This is only *very* lightly tested (ie I tested it on a single kernel
file that used refcount_dec_and_lock())

Linus

(replying to an email from two years ago -- see also
https://lore.kernel.org/linux-kernel/CAHk-=wjZfO9hGqJ2_hGQG3U_XzSh9_XaXze=HgPdvJbgrvASfA@xxxxxxxxxxxxxx/)

Hi Luc,

Are there any plans to add support for __cond_acquires() in sparse?

Marco Elver (Cc-ed) and I are looking into enabling the Clang -Wthread-safety compiler flag for Linux kernel code. If we want to keep the
sparse locking annotations, a first step would be to convert all
__cond_lock() annotations into __cond_acquires(). When I tried to make
that change I noticed that sparse does not yet support
__cond_acquires(). Hence my question about the plan to support
__cond_acquires() in sparse?

Thanks,

Bart.