lkml.org 
[lkml]   [2006]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[patch 1/4] kref: warn kref_put() with unreferenced kref
    This patch adds warning to detect kref_put() with unreferenced kref.

    Signed-off-by: Akinobu Mita <mita@miraclelinux.com>

    lib/kref.c | 14 ++++++++------
    1 files changed, 8 insertions(+), 6 deletions(-)

    Index: 2.6-git/lib/kref.c
    ===================================================================
    --- 2.6-git.orig/lib/kref.c
    +++ 2.6-git/lib/kref.c
    @@ -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);
    WARN_ON(release == NULL);
    WARN_ON(release == (void (*)(struct kref *))kfree);

    @@ -56,12 +57,13 @@ int kref_put(struct kref *kref, void (*r
    * if current count is one, we are the last user and can release object
    * right now, avoiding an atomic operation on 'refcount'
    */
    - if ((atomic_read(&kref->refcount) == 1) ||
    - (atomic_dec_and_test(&kref->refcount))) {
    - release(kref);
    - return 1;
    - }
    - return 0;
    + if (atomic_read(&kref->refcount) == 1)
    + atomic_set(&kref->refcount, 0);
    + else if (!atomic_dec_and_test(&kref->refcount))
    + return 0;
    +
    + release(kref);
    + return 1;
    }

    EXPORT_SYMBOL(kref_init);
    --
    -
    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-24 10:36    [W:2.713 / U:0.368 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site