ChangeSet 1.1803.60.1, 2004/08/02 17:02:58-07:00, greg@kroah.com KREF: shrink the size of struct kref down to just a single atomic_t This was based on a patch from Kiran, but tweaked further by me. Signed-off-by: Ravikiran Thirumalai Signed-off-by: Greg Kroah-Hartman include/linux/kref.h | 7 ++----- lib/kref.c | 26 ++++++++++++-------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff -Nru a/include/linux/kref.h b/include/linux/kref.h --- a/include/linux/kref.h 2004-08-25 14:58:17 -07:00 +++ b/include/linux/kref.h 2004-08-25 14:58:17 -07:00 @@ -18,15 +18,12 @@ #include #include - struct kref { atomic_t refcount; - void (*release)(struct kref *kref); }; -void kref_init(struct kref *kref, void (*release)(struct kref *)); +void kref_init(struct kref *kref); struct kref *kref_get(struct kref *kref); -void kref_put(struct kref *kref); - +void kref_put(struct kref *kref, void (*release) (struct kref *kref)); #endif /* _KREF_H_ */ diff -Nru a/lib/kref.c b/lib/kref.c --- a/lib/kref.c 2004-08-25 14:58:17 -07:00 +++ b/lib/kref.c 2004-08-25 14:58:17 -07:00 @@ -11,23 +11,16 @@ * */ -/* #define DEBUG */ - #include #include /** * kref_init - initialize object. * @kref: object in question. - * @release: pointer to a function that will clean up the object - * when the last reference to the object is released. - * This pointer is required. */ -void kref_init(struct kref *kref, void (*release)(struct kref *kref)) +void kref_init(struct kref *kref) { - WARN_ON(release == NULL); atomic_set(&kref->refcount,1); - kref->release = release; } /** @@ -44,15 +37,20 @@ /** * kref_put - decrement refcount for object. * @kref: object. + * @release: pointer to the function that will clean up the object when the + * last reference to the object is released. + * This pointer is required, and it is not acceptable to pass kfree + * in as this function. * - * Decrement the refcount, and if 0, call kref->release(). + * Decrement the refcount, and if 0, call release(). */ -void kref_put(struct kref *kref) +void kref_put(struct kref *kref, void (*release) (struct kref *kref)) { - if (atomic_dec_and_test(&kref->refcount)) { - pr_debug("kref cleaning up\n"); - kref->release(kref); - } + WARN_ON(release == NULL); + WARN_ON(release == (void (*)(struct kref *))kfree); + + if (atomic_dec_and_test(&kref->refcount)) + release(kref); } EXPORT_SYMBOL(kref_init);