Linux-Doc Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] docs: kref: Clarify the use of two kref_put() in example code
@ 2020-02-13 12:53 Manivannan Sadhasivam
  2020-02-19 10:58 ` Jonathan Corbet
  0 siblings, 1 reply; 4+ messages in thread
From: Manivannan Sadhasivam @ 2020-02-13 12:53 UTC (permalink / raw)
  To: corbet; +Cc: linux-doc, linux-kernel, Manivannan Sadhasivam

Eventhough the current documentation explains that the reference count
gets incremented by both kref_init() and kref_get(), it is often
misunderstood that only one instance of kref_put() is needed in the
example code. So let's clarify that a bit.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 Documentation/kref.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/kref.txt b/Documentation/kref.txt
index 3af384156d7e..c61eea6f1bf2 100644
--- a/Documentation/kref.txt
+++ b/Documentation/kref.txt
@@ -128,6 +128,10 @@ since we already have a valid pointer that we own a refcount for.  The
 put needs no lock because nothing tries to get the data without
 already holding a pointer.
 
+In the above example, kref_put() will be called 2 times in both success
+and error paths. This is necessary because the reference count got
+incremented 2 times by kref_init() and kref_get().
+
 Note that the "before" in rule 1 is very important.  You should never
 do something like::
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] docs: kref: Clarify the use of two kref_put() in example code
  2020-02-13 12:53 [PATCH] docs: kref: Clarify the use of two kref_put() in example code Manivannan Sadhasivam
@ 2020-02-19 10:58 ` Jonathan Corbet
  2020-02-19 11:10   ` Manivannan Sadhasivam
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Corbet @ 2020-02-19 10:58 UTC (permalink / raw)
  To: Manivannan Sadhasivam; +Cc: linux-doc, linux-kernel

On Thu, 13 Feb 2020 18:23:11 +0530
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> wrote:

> Eventhough the current documentation explains that the reference count
> gets incremented by both kref_init() and kref_get(), it is often
> misunderstood that only one instance of kref_put() is needed in the
> example code. So let's clarify that a bit.
> 
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  Documentation/kref.txt | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/kref.txt b/Documentation/kref.txt
> index 3af384156d7e..c61eea6f1bf2 100644
> --- a/Documentation/kref.txt
> +++ b/Documentation/kref.txt
> @@ -128,6 +128,10 @@ since we already have a valid pointer that we own a refcount for.  The
>  put needs no lock because nothing tries to get the data without
>  already holding a pointer.
>  
> +In the above example, kref_put() will be called 2 times in both success
> +and error paths. This is necessary because the reference count got
> +incremented 2 times by kref_init() and kref_get().

Out of curiosity, where have you seen this misunderstanding happening?
I'm not really opposed to this change, but I don't understand why it's
really needed.

Thanks,

jon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] docs: kref: Clarify the use of two kref_put() in example code
  2020-02-19 10:58 ` Jonathan Corbet
@ 2020-02-19 11:10   ` Manivannan Sadhasivam
  2020-02-25 10:39     ` Jonathan Corbet
  0 siblings, 1 reply; 4+ messages in thread
From: Manivannan Sadhasivam @ 2020-02-19 11:10 UTC (permalink / raw)
  To: Jonathan Corbet; +Cc: linux-doc, linux-kernel

Hi Jon,

On Wed, Feb 19, 2020 at 03:58:18AM -0700, Jonathan Corbet wrote:
> On Thu, 13 Feb 2020 18:23:11 +0530
> Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> wrote:
> 
> > Eventhough the current documentation explains that the reference count
> > gets incremented by both kref_init() and kref_get(), it is often
> > misunderstood that only one instance of kref_put() is needed in the
> > example code. So let's clarify that a bit.
> > 
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >  Documentation/kref.txt | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/Documentation/kref.txt b/Documentation/kref.txt
> > index 3af384156d7e..c61eea6f1bf2 100644
> > --- a/Documentation/kref.txt
> > +++ b/Documentation/kref.txt
> > @@ -128,6 +128,10 @@ since we already have a valid pointer that we own a refcount for.  The
> >  put needs no lock because nothing tries to get the data without
> >  already holding a pointer.
> >  
> > +In the above example, kref_put() will be called 2 times in both success
> > +and error paths. This is necessary because the reference count got
> > +incremented 2 times by kref_init() and kref_get().
> 
> Out of curiosity, where have you seen this misunderstanding happening?
> I'm not really opposed to this change, but I don't understand why it's
> really needed.
>

Jakub mistakenly spotted one refcounting issue in one of my patchset:
https://lkml.org/lkml/2020/2/3/926

Then I tried to show him the kernel doc for kref and that's where I got this
example code slightly confusing. And while looking into the log, I noticed that
someone deleted the kref_put in error path mistakenly and that commit got
reverted after that. This issue was even discussed in stack overflow.

http://stackoverflow.com/questions/20093127/why-kref-doc-of-linux-kernel-omits-kref-put-when-kthread-run-fail

So I thought about making it more clear of why the kref_put is needed in error
path.

Thanks,
Mani
 
> Thanks,
> 
> jon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] docs: kref: Clarify the use of two kref_put() in example code
  2020-02-19 11:10   ` Manivannan Sadhasivam
@ 2020-02-25 10:39     ` Jonathan Corbet
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Corbet @ 2020-02-25 10:39 UTC (permalink / raw)
  To: Manivannan Sadhasivam; +Cc: linux-doc, linux-kernel

On Wed, 19 Feb 2020 16:40:55 +0530
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> wrote:

> Jakub mistakenly spotted one refcounting issue in one of my patchset:
> https://lkml.org/lkml/2020/2/3/926
> 
> Then I tried to show him the kernel doc for kref and that's where I got this
> example code slightly confusing. And while looking into the log, I noticed that
> someone deleted the kref_put in error path mistakenly and that commit got
> reverted after that. This issue was even discussed in stack overflow.
> 
> http://stackoverflow.com/questions/20093127/why-kref-doc-of-linux-kernel-omits-kref-put-when-kthread-run-fail
> 
> So I thought about making it more clear of why the kref_put is needed in error
> path.

OK, I've applied it, thanks.

jon

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-13 12:53 [PATCH] docs: kref: Clarify the use of two kref_put() in example code Manivannan Sadhasivam
2020-02-19 10:58 ` Jonathan Corbet
2020-02-19 11:10   ` Manivannan Sadhasivam
2020-02-25 10:39     ` Jonathan Corbet

Linux-Doc Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-doc/0 linux-doc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-doc linux-doc/ https://lore.kernel.org/linux-doc \
		linux-doc@vger.kernel.org
	public-inbox-index linux-doc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-doc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git