Commit 5e5f1d28 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

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: default avatarRavikiran Thirumalai <kiran@in.ibm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 81fd00e2
...@@ -18,15 +18,12 @@ ...@@ -18,15 +18,12 @@
#include <linux/types.h> #include <linux/types.h>
#include <asm/atomic.h> #include <asm/atomic.h>
struct kref { struct kref {
atomic_t refcount; 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); 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_ */ #endif /* _KREF_H_ */
...@@ -11,23 +11,16 @@ ...@@ -11,23 +11,16 @@
* *
*/ */
/* #define DEBUG */
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/module.h> #include <linux/module.h>
/** /**
* kref_init - initialize object. * kref_init - initialize object.
* @kref: object in question. * @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); atomic_set(&kref->refcount,1);
kref->release = release;
} }
/** /**
...@@ -44,15 +37,20 @@ struct kref *kref_get(struct kref *kref) ...@@ -44,15 +37,20 @@ struct kref *kref_get(struct kref *kref)
/** /**
* kref_put - decrement refcount for object. * kref_put - decrement refcount for object.
* @kref: 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)) { WARN_ON(release == NULL);
pr_debug("kref cleaning up\n"); WARN_ON(release == (void (*)(struct kref *))kfree);
kref->release(kref);
} if (atomic_dec_and_test(&kref->refcount))
release(kref);
} }
EXPORT_SYMBOL(kref_init); EXPORT_SYMBOL(kref_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment