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)
1 Answer 1
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 #define
d 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.