From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Tobin C. Harding" <tobin@kernel.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kobject: Improve docs for kobject_add/del
Date: Sun, 28 Apr 2019 18:16:54 +0200 [thread overview]
Message-ID: <20190428161654.GA14579@kroah.com> (raw)
In-Reply-To: <20190428004810.11376-1-tobin@kernel.org>
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@kernel.org>
> ---
>
> 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
prev parent reply other threads:[~2019-04-28 16:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-28 0:48 [PATCH] kobject: Improve docs for kobject_add/del Tobin C. Harding
2019-04-28 16:16 ` Greg Kroah-Hartman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190428161654.GA14579@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=tobin@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.