From: Peter Zijlstra Date: Thu, 30 Jun 2022 17:43:20 +0200 Subject: [Cluster-devel] [RFC 1/2] refcount: add __cond_lock() for conditional lock refcount API In-Reply-To: <20220630135934.1799248-2-aahringo@redhat.com> References: <20220630135934.1799248-1-aahringo@redhat.com> <20220630135934.1799248-2-aahringo@redhat.com> Message-ID: List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Thu, Jun 30, 2022 at 09:59:33AM -0400, Alexander Aring wrote: > This patch adds the __cond_lock() macro to refcounts conditional lock > API. Currently sparse cannot detect the conditional lock handling of > refcount_dec_and_lock() functionality and prints a context imbalance > warning like: > > warning: context imbalance in 'put_rsb' - unexpected unlock > > with this patch and having the refcount_dec_and_lock() functionality > inside the if condition to decide whenever doing unlock or not the > warning disappears. > > The patch follows a similar naming scheme like raw_spin_trylock() by > adding a "raw_" prefix to refcount_dec_and_lock() functionality and > introduce a macro for the replaced functions that uses __cond_lock() > to signal that an acquire depends on the return value of the passed > function. > > A cast to bool seems to be necessary because __cond_lock() does return a > non-boolean scalar type. I hate the __cond_lock() think with a passions. Please just fix sparse to not suck.