Re: [PATCH] kobject: Improve docs for kobject_add/del

From: Greg Kroah-Hartman
Date: Sun Apr 28 2019 - 12:17:03 EST


On Sun, Apr 28, 2019 at 10:48:10AM +1000, Tobin C. Harding wrote:
> There is currently some confusion on how to wind back
> kobject_init_and_add() during the error paths in code that uses this
> function.
>
> Add documentation to kobject_add() and kobject_del() to help clarify the
> usage.
>
> Signed-off-by: Tobin C. Harding <tobin@xxxxxxxxxx>
> ---
>
> The assumption is that this is the correct usage, and that's what I've
> tried to document. Is this correct?
>
> void fn(void)
> {
> int ret;
>
> ret = kobject_init_and_add(kobj, ktype, NULL, "foo");
> if (ret) {
> kobject_put(kobj);
> return -1;

Don't make up error numbers, use a real one :)

> }
>
> ret = some_init_fn();
> if (ret)
> goto err;
>
> ret = some_other_init_fn();
> if (ret)
> goto other_err;
>
> kobject_uevent(kobj, KOBJ_ADD);
> return 0;
>
> other_err:
> other_clean_up_fn();
> err:
> kobject_del(kobj);
> return ret;
> }

Yes, this looks correct.

I've queued both of these patches up now, thanks!

greg k-h