Re: [ofa-general] IB kernel modules and the kobject release() method

From: Kay Sievers
Date: Tue Aug 11 2009 - 08:56:53 EST


On Mon, Aug 10, 2009 at 22:33, Roland Dreier<rdreier@xxxxxxxxx> wrote:
>
> Â> No, it still makes sense :)
>
> So what's the fix for this?

The fix is not to embed any kobject/struct device into an object whose
lifetime is not controlled by the kobject. The kobject should just be
a pointer then, and not inlined in the same memory the object uses,
which needs the kobject. The entire kobject embedding/release logic
works only properly if the kobject can own/control the lifetime of the
enclosing object - if not, it should just not be embedded.

> If even you have trouble understanding
> kobject lifetimes

I don't think we have trouble understanding that, but we are
hopelessly lost running after people who "optimize" the use of
kobjects/struct device to save an allocation or a separate dynamic
object.

> and the requirement for a release function, is there
> hope for anyone else?

Almost all uses where kobjects/struct device are statically allocated,
an object embeds more than a single kobject, or the embedded kobject
does not control the lifetime of the enclosing object, is just a
mis-use of kobjects.

Not sure, maybe it needs a simpler API to use non-embedded kobjects,
to make it easier to reach the originating object from the kobject.
That might not be obvious how to do that in some cases.

Kay
--
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/