From bf6f45b8d33dde2d2aadb93781a89421d1a0fa35 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 30 Jan 2006 06:19:35 +0100 Subject: [PATCH] --- yaml --- r: 22000 b: refs/heads/master c: 8b5536bbee53620f8d5f367987e5727ba36d886d h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/lib/kref.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 5d821dc5893e..5faf641962cf 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 489447380a2921ec0e9154f773c44ab3167ede4b +refs/heads/master: 8b5536bbee53620f8d5f367987e5727ba36d886d diff --git a/trunk/lib/kref.c b/trunk/lib/kref.c index 0d07cc31c818..4a467faf1367 100644 --- a/trunk/lib/kref.c +++ b/trunk/lib/kref.c @@ -52,7 +52,12 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref)) WARN_ON(release == NULL); WARN_ON(release == (void (*)(struct kref *))kfree); - if (atomic_dec_and_test(&kref->refcount)) { + /* + * 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; }