aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <greg@kroah.com>2004-08-02 03:02:58 -0700
committerGreg Kroah-Hartman <greg@kroah.com>2004-08-02 03:02:58 -0700
commit5e5f1d28c09dd694a1f6ddb23265ae385d6bfa68 (patch)
tree2a8a3a7ae3223cda17f2049fccb1d290d6512ebe /lib
parent81fd00e2e58911325c794b6f98d683ecb7db2b04 (diff)
downloadhistory-5e5f1d28c09dd694a1f6ddb23265ae385d6bfa68.tar.gz
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 <kiran@in.ibm.com> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/kref.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/kref.c b/lib/kref.c
index ee141adbf2e558..1015d5ee698c13 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -11,23 +11,16 @@
*
*/
-/* #define DEBUG */
-
#include <linux/kref.h>
#include <linux/module.h>
/**
* 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 @@ struct kref *kref_get(struct kref *kref)
/**
* 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);