From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Driver Core patches for 2.6.9-rc1
Date: Wed, 25 Aug 2004 15:36:26 -0700 [thread overview]
Message-ID: <1093473386452@kroah.com> (raw)
In-Reply-To: <20040825223503.GA27072@kroah.com>
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 <kiran@in.ibm.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
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 <linux/types.h>
#include <asm/atomic.h>
-
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 <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 @@
/**
* 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);
next prev parent reply other threads:[~2004-08-25 22:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-25 22:35 [BK PATCH] Driver Core patches for 2.6.9-rc1 Greg KH
2004-08-25 22:36 ` Greg KH [this message]
2004-08-25 22:36 ` [PATCH] " Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-25 22:36 ` Greg KH
2004-08-26 2:04 ` Benjamin Herrenschmidt
2004-08-26 4:10 ` Greg KH
2004-08-26 12:26 ` Jean Delvare
2004-08-26 23:33 ` Benjamin Herrenschmidt
2004-08-27 10:16 ` Jean Delvare
-- strict thread matches above, loose matches on Subject: below --
2004-08-26 18:15 Margit Schubert-While
[not found] <200408261957.58105.margitsw@t-online.de>
[not found] ` <5.1.0.14.2.20040908220127.02a9daa8@pop.t-online.de>
2004-09-08 20:21 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1093473386452@kroah.com \
--to=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox