Re: kobjects, sysfs and the driver model make my head hurt

From: Greg KH (greg@kroah.com)
Date: Sun Jul 06 2003 - 11:46:26 EST


On Sun, Jul 06, 2003 at 05:33:53PM +0100, Matthew Wilcox wrote:
>
> struct kobject * kobject_get(struct kobject * kobj)
> {
> if (kobj) {
> WARN_ON(!atomic_read(&kobj->refcount));
> atomic_inc(&kobj->refcount);
> }
> return kobj;
> }

That's nice. Remember, we used to have a lock in there, that's why the
code doesn't look that clean after it was removed.

> But why return anything? Which looks clearer?
>
> (a) kobj = kobject_get(kobj);

This is the way to call kobject_get(), as the object we get after the
function returns is the one we can then safely use.

> The first one makes me think that kobject_get might return a different
> kobject than the one I passed in. That doesn't make much sense.

Think of it as, "now we can use this kobject, not the one before calling
kobject_get()".

thanks,

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



This archive was generated by hypermail 2b29 : Mon Jul 07 2003 - 22:00:27 EST