lkml.org 
[lkml]   [2006]   [Apr]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [patch 1/4] kref: warn kref_put() with unreferenced kref
    On Tue, Apr 25, 2006 at 12:34:10PM +0800, Akinobu Mita wrote:
    > On Mon, Apr 24, 2006 at 08:51:28PM -0700, Greg KH wrote:
    > > > @@ -49,6 +49,7 @@ void kref_get(struct kref *kref)
    > > > */
    > > > int kref_put(struct kref *kref, void (*release)(struct kref *kref))
    > > > {
    > > > + WARN_ON(atomic_read(&kref->refcount) < 1);
    > >
    > > How can this ever be true? If the refcount _ever_ goes below 1, the
    > > object is freed.
    >
    > 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 become 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);

    But again, if this happens the memory will be freed. So again,
    CONFIG_DEBUG_SLAB will catch this kind of thing.

    Is there some reason you created these patches? Were you trying to
    debug something that was tracked down to a kref issue?

    thanks,

    greg k-h
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2006-04-25 07:18    [W:0.019 / U:177.976 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site