Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)
spin_unlock_irqrestore(&uidhash_lock, flags);
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
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


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.