From: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
To: linux-sparse@vger.kernel.org
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Will sparse ever work correctly with guard?
Date: Thu, 23 Oct 2025 07:51:10 -0700 [thread overview]
Message-ID: <54b7bc6c-8e30-4924-b700-bcb87b79be5a@oss.qualcomm.com> (raw)
In code I maintain there are places where we are now trying to use guard to
cleanup locks. But 'make W=1 C=1' is complaining:
warning: context imbalance in '<function>' - wrong count at exit
And lore shows this is not a new complaint:
[PATCH v2] parse: handle __cleanup__ attribute
https://lore.kernel.org/all/Zag2fYsyJDtDR7a6@google.com/
For some reason scoped_guard doesn't have this issue:
Re: [PATCH v1 3/3] cgroup: add lock guard support for others
https://lore.kernel.org/all/722C5824-0381-4E43-B8AE-AE8503CFF51E@gmail.com/
But using scoped_guard then requires an additional level of indentation in the
code.
So I'm wondering if there is any chance that sparse will be able to handle
guard in the same manner as scoped_guard?
The code I maintain currently has no sparse issues, so if this cannot be fixed
then I'll have to decide whether to use scoped_guard (and indent the body of
those functions) or just keep the traditional "goto cleanup" code.
/jeff
reply other threads:[~2025-10-23 14:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=54b7bc6c-8e30-4924-b700-bcb87b79be5a@oss.qualcomm.com \
--to=jeff.johnson@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--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).