Re: [RFC PATCH] debugobject: add support for kref

From: Thomas Gleixner
Date: Thu Oct 24 2013 - 10:48:53 EST


On Thu, 24 Oct 2013, Sebastian Andrzej Siewior wrote:
>
> struct kref {
> atomic_t refcount;
> @@ -32,6 +33,9 @@ struct kref {
> static inline void kref_init(struct kref *kref)
> {
> atomic_set(&kref->refcount, 1);
> +#ifdef CONFIG_DEBUG_OBJECTS_KREF
> + debug_object_init(kref, NULL);

I rather prefer to have a debug_obj_descr handed in. It also should
activate the object, because then you can catch freeing of an active
kref as well. With state INIT the free checks are not triggering.

> /**
> @@ -70,6 +74,12 @@ static inline int kref_sub(struct kref *kref, unsigned int count,
> {
> WARN_ON(release == NULL);
>
> +#ifdef CONFIG_DEBUG_OBJECTS_KREF
> + if (!debug_object_is_tracked(kref)) {
> + debugobj_kref_splat(kref, release);
> + return 0;

Why can't you use debug_object_active_state(kref, descr, 0, 0)? All it
needs is a return value which tells you whether the object is tracked
and its state is ACTIVE.

> + }
> +#endif
> if (atomic_sub_and_test((int) count, &kref->refcount)) {
> release(kref);
> return 1;

What calls debug_object_free() for the kref? You seem to add tracking
objects without ever releasing them. Are you relying on kfree removing
the inactive object from the debugobjects tracking list?

Not really a good idea. There might be some different release function
than kfree. And it relies on DEBUG_OBJECTS_FREE being enabled.

So an explicit call to debug_objects_free() before release(kref) is
required. Otherwise your new check is going to fail even when the kref
is gone already.

Thanks,

tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/