From: YuLicheng <gancuimian@hotmail.com>
To: <linux-doc@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <roel.kluin@gmail.com>
Subject: kref doc: Why kref kernel doc omits kref_put when kthread_run fail
Date: Thu, 21 Nov 2013 10:42:18 +0800 [thread overview]
Message-ID: <BLU171-DS35B00C010728ACFB2F8DF9D3E10@phx.gbl> (raw)
The document is /Documentation/kerf.txt, and I'm referring to v3.12:
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/Documentation/kref.txt?id=v3.12
Part of the first example in the document is attached below.
In my_data_handler(), kref_init() already put 1 to refcount, and kref_get()
next made the refcount 2. But if kthread_run() fails, only one kref_put()
will
take place (right after the out tag), it renders the refcount to be 1 at
last,
and the data will never be freed.
int my_data_handler(void)
{
int rv = 0;
struct my_data *data;
struct task_struct *task;
data = kmalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
kref_init(&data->refcount);
kref_get(&data->refcount);
task = kthread_run(more_data_handling, data, "more_data_handling");
if (task == ERR_PTR(-ENOMEM)) {
rv = -ENOMEM;
goto out;
}
.
. do stuff with data here
.
out:
kref_put(&data->refcount, data_release);
return rv;
}
I also noticed that there once was a kref_put() before "goto out" in the doc
before some point of 2009, but it was removed by a patch that claimed that
this
kref_put() was redudent.
The patch commit is:
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/Documentation/kref.txt?id=8f1ecc9fbc5b223e4f5d5bb8bcd6f5672c4bc4b6
Is this a bug or maybe I missed something?
Licheng
reply other threads:[~2013-11-21 2:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=BLU171-DS35B00C010728ACFB2F8DF9D3E10@phx.gbl \
--to=gancuimian@hotmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roel.kluin@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®