From dc01d0035a3efd4e12b4aabf7eaae4d69a263978 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 8 Mar 2005 18:00:20 -0800 Subject: [PATCH] kref: make kref_put return if this was the last put call. This is needed for the upcoming klist code from Pat. Signed-off-by: Greg Kroah-Hartman --- lib/kref.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/kref.c b/lib/kref.c index 2218b7ae7db6..0d07cc31c818 100644 --- a/lib/kref.c +++ b/lib/kref.c @@ -42,14 +42,21 @@ void kref_get(struct kref *kref) * in as this function. * * Decrement the refcount, and if 0, call release(). + * Return 1 if the object was removed, otherwise return 0. Beware, if this + * function returns 0, you still can not count on the kref from remaining in + * memory. Only use the return value if you want to see if the kref is now + * gone, not present. */ -void kref_put(struct kref *kref, void (*release) (struct kref *kref)) +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 (atomic_dec_and_test(&kref->refcount)) { release(kref); + return 1; + } + return 0; } EXPORT_SYMBOL(kref_init); -- cgit v1.2.3