make all kref debugging checks new config option. Signed-off-by: Akinobu Mita CC: Greg KH CC: Patrick Mochel 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) +{ + WARN_ON(!atomic_read(&kref->refcount)); +} +static void kref_put_debug_check(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); +} +#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 --