Re: Question about (or bug in?) the kobject implementation

From: Greg KH
Date: Wed Mar 03 2004 - 16:52:09 EST


On Fri, Feb 27, 2004 at 11:02:34PM -0500, Alan Stern wrote:
> On Fri, 27 Feb 2004, Greg KH wrote:
>
> > Seriously, once kobject_del() is called, you can't safely call
> > kobject_get() anymore on that object.
> >
> > If you can think of a way we can implement this in the code to prevent
> > people from doing this, please send a patch. We've been getting by
> > without such a "safeguard" so far...
>
> The problem is unsolvable. Let me explain...
>
> We're actually discussing two different questions here.
>
> A. Is it okay to call kobject_add() after calling kobject_del() --
> this was my original question.

No, this is not ok. It might happen to work, but it is not valid.

> B. Can we prevent people from doing kobject_get() after the kobject's
> refcount has dropped to 0?

By saying, "you can not call kobject_get() on a object that you know is
released with kobject_del()". If you already have a valid reference,
you can always call kobject_get(). But once you call kobject_del() that
pointer you passed should not be passed to kobject_get() as it may now
be gone.

Does that help?

thanks,

greg k-h
-
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/