Re: [PATCH 2.6.12-rc4] cpuset exit NULL dereference fix
From: Linus Torvalds
Date: Thu May 26 2005 - 10:44:17 EST
On Thu, 26 May 2005, Robin Holt wrote:
>
> Why not change the atomic into a lock and a refcount. Grab the lock before
> each increment/decrement of the refcount and only continue with the removal
> code when the refcount reaches 0.
For this, there is a nice
atomic_dec_and_lock()
function that is the same as "atomic_dec_and_test()", except it grabs the
lock if the count decrements to zero.
I'm surprised people haven't picked up on it - it's been around for a
while, the VFS layer uses it for some quite fundamental data structures
(inode and dcache refcounts), and it's even documented in "atomic_ops.txt"
And it's _designed_ for refcountign things like this.
Basic rule of kernel programming: if a globally visible object does not
have a refcount, IT IS A BUG.
Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/