Robert P. J. Day | 19 Jul 13:46
Favicon

some newbie questions about __attribute__((context,...))


  (if there's a good writeup on this, or a previous mailing post
explaining this, a pointer to that will do just fine.)

  i'm trying to understand how this context checking is actually done
by sparse.  from the sparse man page:

"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"
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.

  so, to try to keep things simple, what is happening in the
background with code like this:

=====
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;
(Continue reading)

Johannes Berg | 19 Jul 14:42
Favicon

Re: some newbie questions about __attribute__((context,...))


> "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.
(Continue reading)


Gmane