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

From: Alan Stern
Date: Wed Mar 03 2004 - 17:17:58 EST


On Wed, 3 Mar 2004, Greg KH wrote:

> On Fri, Feb 27, 2004 at 11:02:34PM -0500, Alan Stern wrote:
> > 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.

I want to understand _why_ it is not valid. Can you explain please?

>From what you said earlier, I got the impression that calling _add() after
_del() is illegal because it runs the risk that the refcount may be 0 and
the object may be gone. But if you have a separate valid reference, that
can't happen. Would it be legal then, or is there more to it?


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

Alan Stern

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