Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
From: Alexander Aring <aahringo@redhat.com>
To: linux-sparse@vger.kernel.org
Cc: cluster-devel <cluster-devel@redhat.com>
Subject: sparse warnings related to kref_put_lock() and refcount_dec_and_lock()
Date: Mon, 27 Jun 2022 11:15:17 -0400	[thread overview]
Message-ID: <CAK-6q+hd-L54cqOiFNuufS2_VF5XS0R8cjQL7es8921+2u3uwQ@mail.gmail.com> (raw)

Hi,

I recently converted to use kref_put_lock() in fs/dlm subsystem and
now I get the following warning in sparse:

warning: context imbalance in 'put_rsb' - unexpected unlock

It seems sparse is not able to detect that there is a conditional
requirement that the lock passed to kref_put_lock() (or also
refcount_dec_and_lock()) is locked or not. I evaluate the return value
to check if kref_put_lock() helds the lock and unlock it then. The
idea is that the lock needs only to be held when the refcount is going
to be zero.

It seems other users unlock the lock at the release callback of
kref_put_lock() and annotate the callback with "__releases()" which
seems to work to avoid the sparse warning. However this works if you
don't have additional stack pointers which you need to pass to the
release callback.

My question would be is this a known problem and a recommended way to
avoid this sparse warning (maybe just for now)?

Thanks.

- Alex


             reply	other threads:[~2022-06-27 15:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 15:15 Alexander Aring [this message]
2022-06-27 18:42 ` sparse warnings related to kref_put_lock() and refcount_dec_and_lock() Luc Van Oostenryck
2022-06-28  0:56   ` Alexander Aring
2022-06-28  1:06     ` Alexander Aring
2022-06-28  8:58       ` Luc Van Oostenryck
2022-06-28 13:26         ` Alexander Aring
2022-06-28 17:27         ` Linus Torvalds
2022-06-29 14:42           ` Alexander Aring

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=CAK-6q+hd-L54cqOiFNuufS2_VF5XS0R8cjQL7es8921+2u3uwQ@mail.gmail.com \
    --to=aahringo@redhat.com \
    --cc=cluster-devel@redhat.com \
    --cc=linux-sparse@vger.kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).