On Tue, Apr 25, 2006 at 04:21:38PM +0800, Akinobu Mita wrote:
> This patch adds warning to detect kref_put() with unreferenced object.
>
> The idea of detection kref_put() with unreferenced object was stolen
> from BUG_ON()es in blocks/ll_rw_blk.c and fs/bio.c
>
> ll_rw_blk.c: BUG_ON(atomic_read(&ioc->refcount) == 0);
>
> bio.c: BIO_BUG_ON(!atomic_read(&bio->bi_cnt));
>
> But the kref counter usually does not fall to zero. Because kref is
> trying to reduce the number of atomic_dec_and_test()
>
> So this patch also set kref counter to zero here:
>
> + if (atomic_read(&kref->refcount) == 1)
> + atomic_set(&kref->refcount, 0);
I really don't see how this is going to make it easier to debug
anything. Remember, when a kref goes to 0, it is automatically freed.
So any code that tries to use it afterward just dies a horrible death,
if CONFIG_DEBUG_SLAB is enabled.
And please be careful, you can't replace all usages of atomic_t counters
in the kernel with krefs...
thanks,
greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]