linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: "Robert P. J. Day" <rpjday@crashcourse.ca>
Cc: Sparse mailing list <linux-sparse@vger.kernel.org>
Subject: Re: some newbie questions about __attribute__((context,...))
Date: Sat, 19 Jul 2008 14:42:20 +0200	[thread overview]
Message-ID: <1216471340.29432.3.camel@johannes.berg> (raw)
In-Reply-To: <alpine.LFD.1.10.0807190737340.24056@localhost.localdomain> (sfid-20080719_135053_191810_F7BD1A44)

[-- Attachment #1: Type: text/plain, Size: 2224 bytes --]


> "Functions with the extended attribute
> __attribute__((context(expression,in_context,out_context)) require the
> context expression (for instance, a lock) to have the value in_context
> (a constant nonnegative integer) when called, and return with the
> value out_context (a constant nonnegative integer)."
> 
>   fair enough, but what are the possibilities for that "expression"

None. It's currently mostly ignored. I posted patches to fix this, which
had problems, and the fixes to those patches haven't been merged yet.

With my patches, the possibilities are either an expression that sparse
can resolve, e.g.

void do_lock(void *lock) __attribute__((context(lock,0,1))) {...}

or for compatibility anything else that is then treated as a constant:

void do_lock(void) __attribute__((context(GLOBAL_LOCK,0,1))) {...}

> and what exactly is being compared to the values of 0 or 1?  sure, a
> lock is an obvious candidate, but you can't really simply be comparing
> the value of a lock to 0 or 1 -- a lock is a *structure* which doesn't
> have a simple value of 0 or 1.

Sparse internally tracks the "value" of such a context. My examples
above would increase the context in the function, and every time that
function is called the context is increased, and if such a context is
"leaked" then sparse will complain it isn't 0.

> static void *aarp_seq_start(struct seq_file *seq, loff_t *pos)
>         __acquires(aarp_lock)
> {
>         struct aarp_iter_state *iter = seq->private;
> 
>         read_lock_bh(&aarp_lock);
>         iter->table     = resolved;
>         iter->bucket    = 0;
> 
>         return *pos ? iter_next(iter, pos) : SEQ_START_TOKEN;
> }
> =====
> 
>   and how is that call to read_lock_bh() changing the "context" value
> of the object aarp_lock?  thanks for any enlightenment.

Well, read_lock_bh() acquires the context named "aarp_lock", and
aarp_seq_start is annotated to also do that. If you write

void foo()
{
	read_lock_bh(&aarp_lock);
}

then sparse will complain that the context is leaked in foo.

If you really want to do any serious work with sparse's context tracking
I can only suggest to apply my patches.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

      reply	other threads:[~2008-07-19 12:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-19 11:49 some newbie questions about __attribute__((context,...)) Robert P. J. Day
2008-07-19 12:42 ` Johannes Berg [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=1216471340.29432.3.camel@johannes.berg \
    --to=johannes@sipsolutions.net \
    --cc=linux-sparse@vger.kernel.org \
    --cc=rpjday@crashcourse.ca \
    /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).