From: Christopher Li <sparse@chrisli.org>
To: Josh Triplett <josh@joshtriplett.org>
Cc: Petr Muller <afri@afri.cz>, linux-sparse@vger.kernel.org
Subject: Re: Detection of locking one lock twice
Date: Tue, 5 Jan 2010 22:58:37 -0800 [thread overview]
Message-ID: <70318cbf1001052258j407e52d2j6adabef88558d7f1@mail.gmail.com> (raw)
In-Reply-To: <20100104074825.GC2423@feather>
On Sun, Jan 3, 2010 at 11:48 PM, Josh Triplett <josh@joshtriplett.org> wrote:
>> void fction(int a)
>> {
>> lock();
>> lock();
>> unlock();
>> unlock();
>> }
>> 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?
Sorry I am late to the party. I think sparse does not complain on this
code because sparse has no way to track *which* lock it is taking.
Some thing like:
lock(A);
lock(B);
unlock(B);
unlock(A);
It is perfectly fine. So sparse is not suppose to complain there.
> 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".
You can interpret it that way, but that is not how I see it.
The context is not suppose to go to negative, that is why we have 'in' and 'out'
context. When a function perform unlock, you are suppose to give a
positive value in
'in' context to avoid geting negative. As long as the context does not
go negative,
sparse only care about the delta of 'in' and 'out' value. It counts
the context to
the exact number. See the following code:
if (insn->opcode == OP_RET)
return entry != exit ? imbalance(ep, bb, entry, exit, "wrong count
at exit") : 0;
So I don't think it is a bug. If you disagree, please give me more detail.
Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2010-01-06 6:58 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
2010-01-06 6:58 ` Christopher Li [this message]
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=70318cbf1001052258j407e52d2j6adabef88558d7f1@mail.gmail.com \
--to=sparse@chrisli.org \
--cc=afri@afri.cz \
--cc=josh@joshtriplett.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 NNTP newsgroup(s).