Messages in this thread Patch in this message | | | Date | Mon, 24 Apr 2006 16:33:35 +0800 | From | Akinobu Mita <> | Subject | [patch 2/4] kref debugging config option |
| |
This patch converts all WARN_ON() in kref code to BUG_ON(). And split them into new DEBUG_KREF config option.
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
lib/Kconfig.debug | 7 +++++++ lib/kref.c | 30 +++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-)
Index: 2.6-git/lib/Kconfig.debug =================================================================== --- 2.6-git.orig/lib/Kconfig.debug +++ 2.6-git/lib/Kconfig.debug @@ -130,6 +130,13 @@ config DEBUG_KOBJECT If you say Y here, some extra kobject debugging messages will be sent to the syslog. +config DEBUG_KREF + bool "kref debugging" + depends on DEBUG_KERNEL + help + This option enables addition error checking for kref, + library routines for handling generic reference counted objects. + config DEBUG_HIGHMEM bool "Highmem debugging" depends on DEBUG_KERNEL && HIGHMEM Index: 2.6-git/lib/kref.c =================================================================== --- 2.6-git.orig/lib/kref.c +++ 2.6-git/lib/kref.c @@ -20,16 +20,38 @@ */ void kref_init(struct kref *kref) { - atomic_set(&kref->refcount,1); + atomic_set(&kref->refcount, 1); } +#ifdef CONFIG_DEBUG_KREF +static void kref_get_debug_check(struct kref *kref) +{ + BUG_ON(!atomic_read(&kref->refcount)); +} +static void kref_put_debug_check(struct kref *kref, + void (*release)(struct kref *kref)) +{ + BUG_ON(atomic_read(&kref->refcount) < 1); + BUG_ON(release == NULL); + BUG_ON(release == (void (*)(struct kref *))kfree); +} +#else +static void kref_get_debug_check(struct kref *kref) +{ +} +static void kref_put_debug_check(struct kref *kref, + void (*release)(struct kref *kref)) +{ +} +#endif + /** * kref_get - increment refcount for object. * @kref: object. */ void kref_get(struct kref *kref) { - WARN_ON(!atomic_read(&kref->refcount)); + kref_get_debug_check(kref); atomic_inc(&kref->refcount); } @@ -49,9 +71,7 @@ void kref_get(struct kref *kref) */ int kref_put(struct kref *kref, void (*release)(struct kref *kref)) { - WARN_ON(atomic_read(&kref->refcount) < 1); - WARN_ON(release == NULL); - WARN_ON(release == (void (*)(struct kref *))kfree); + kref_put_debug_check(kref, release); /* * if current count is one, we are the last user and can release object -- - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |