linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Russ Cox <rsc@swtch.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: sparse context tags
Date: Mon, 12 Mar 2007 17:32:34 -0700	[thread overview]
Message-ID: <20070313003234.GA4640@chrisli.org> (raw)
In-Reply-To: <ee9e417a0703121537p49657eai662b3dce82c7af5d@mail.gmail.com>

On Mon, Mar 12, 2007 at 06:37:34PM -0400, Russ Cox wrote:
> Is the optional leading context argument
> (the x in __attribute__((context(x, 0, 1)))
> documented anywhere?  Apologies if this is
> a FAQ, but I've looked.

I don't know about the document. The x is mostly
for human reading currently. Sparse does not use
it yet.

> 
> Failing that, can someone enlighten me about
> why sparse doesn't find any problems with
> the function bad() below?  I am using sparse-0.2.

That is because sparse can't distinguish which lock is
acquired. It is actually hard to get that information.
Even though the expression is the same, the actual lock
might be different.

e.g.

redlock(foo->redlock);
foo = bar;
redunlock (foo->redlock);


Depend on the value of foo, even the same expression can
mean different locks.

So sparse currently just stack all the lock level into one place,
it will complain about any lock level that is has mismatch.


> void
> bad(redlock_t *r, bluelock_t *b)
> {
> 	redlock(r);
> 	blueunlock(b);
> }

Sparse sees:

Some lock acquired and some lock release exactly once in the function.
Nothing to complain.

How ever, if you do:

#define __acquires_red(x) __attribute__((context(x, 0, 1)))
#define __releases_red(x) __attribute__((context(x, 1, 0)))

#define __acquires_blue(x) __attribute__((context(x, 0, 1024)))
#define __releases_blue(x) __attribute__((context(x, 1024, 0)))

Assume your redlock level did not go up to 1024, then:

void redlock(redlock_t *r) __acquires_red(r);

void bluelock(redlock_t *r) __acquires_blue(r);
void blueunlock(redlock_t *r) __releases_blue(r);


You will get the complain about lock level not match at exit.

Chris

  reply	other threads:[~2007-03-13  1:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-12 22:37 sparse context tags Russ Cox
2007-03-13  0:32 ` Christopher Li [this message]
2007-03-13  1:31   ` Pavel Roskin

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=20070313003234.GA4640@chrisli.org \
    --to=sparse@chrisli.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=rsc@swtch.com \
    /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).