From: Josh Triplett <josh@joshtriplett.org>
To: Petr Muller <afri@afri.cz>
Cc: linux-sparse@vger.kernel.org
Subject: Re: Detection of locking one lock twice
Date: Sun, 3 Jan 2010 23:48:25 -0800 [thread overview]
Message-ID: <20100104074825.GC2423@feather> (raw)
In-Reply-To: <1261440567.5039.12.camel@localhost.localdomain>
On Tue, Dec 22, 2009 at 01:09:27AM +0100, Petr Muller wrote:
> I'm playing with sparse a bit, especially the context/locking problem
> detecting stuff. I'm trying to create simple context updating
> lock/unlock, everything works as I would expect except for this case
> (I've reduced it as much as possible) :
>
> #ifdef __CHECKER__
> #define __acquires(x) __attribute__((context (x, 0, 1)))
> #define __releases(x) __attribute__((context (x, 1, 0)))
> #define __acquire(x) __context__(x,1)
> #define __release(x) __context__(x,-1)
> #else
> (...)
> #endif
>
> (...)
>
> void lock(void)
> __acquires(i)
> {
> __acquire(i);
> }
>
> void unlock(void)
> __releases(i)
> {
> __release(i);
> }
>
> void fction(int a)
> {
> lock();
> lock();
> unlock();
> unlock();
> }
>
> int main(void){
> fction(1);
> return 0;
> }
>
> Sparse gives no warning in this code - I would expect that second call
> to lock() would violate the 'in' limit of __acquires attribute, but it
> does not. I'm wondering if this is actually a problem in sparse, or am I
> doing something wrong?
As far as I know, Sparse currently treats the "in" context as a minimum
requirement, not an exact requirement. Thus, a context of 0 ends up
meaning "may or may not hold the lock", while 1 means "must hold the
lock at least once".
I think that needs fixing.
- Josh Triplett
next prev parent reply other threads:[~2010-01-04 8:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-22 0:09 Detection of locking one lock twice Petr Muller
2010-01-04 7:48 ` Josh Triplett [this message]
2010-01-06 6:58 ` Christopher Li
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=20100104074825.GC2423@feather \
--to=josh@joshtriplett.org \
--cc=afri@afri.cz \
--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 NNTP newsgroup(s).