Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Can any one please explain this piece of code I found in the linux kernel source. I see a lots of code like this in linux and minix kernel but dont seem to find what it does (even if C compilers support that kind of function definition)

/* IRQs are disabled and uidhash_lock is held upon function entry.
 * IRQ state (as stored in flags) is restored and uidhash_lock released
 * upon function exit.
 */
static void free_user(struct user_struct *up, unsigned long flags)
__releases(&uidhash_lock)
{
uid_hash_remove(up);
spin_unlock_irqrestore(&uidhash_lock, flags);
key_put(up->uid_keyring);
key_put(up->session_keyring);
kmem_cache_free(uid_cachep, up);
}

I cannot find out if this reference __releases(&uidhash_lock) before the parenthesis starts is allowed OR supported. (It sure is supported as it is in the linux kernel)

share|improve this question

1 Answer 1

up vote 9 down vote accepted

These are annotations used by Sparse, the Static Analysis Tool for the Linux Kernel, originally written by Linus Torvalds. When compiled normally, without Sparse, they are simply #defined away to nothing.

The definitions are in include/linux/compiler.h:

# define __releases(x)  __attribute__((context(x,1,0)))

This one uses the __attribute__ non-standard GCC extension.

This specific annotation is paired with another one called __acquires(x), which allows Sparse to determine whether the code paths which acquire and release a specific lock are correctly balanced.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.