linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks
@ 2020-09-10  5:52 Stephen Boyd
  2020-09-10  5:52 ` [PATCH v3 2/2] idr: Document that ida_simple_{get,remove}() are deprecated Stephen Boyd
  2020-09-10 16:19 ` [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Boyd @ 2020-09-10  5:52 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Greg KH, Tri Vo, Jonathan Corbet, linux-doc,
	Matthew Wilcox

The documentation for these functions indicates that callers don't need
to hold a lock while calling them, but that documentation is only in one
place under "IDA Usage". Let's state the same information on each IDA
function so that it's clear what the calling context requires.
Furthermore, let's document ida_simple_get() with the same information
so that callers know how this API works.

Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Tri Vo <trong@android.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/idr.h | 9 ++++++---
 lib/idr.c           | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/linux/idr.h b/include/linux/idr.h
index 3ade03e5c7af..b235ed987021 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -263,7 +263,8 @@ void ida_destroy(struct ida *ida);
  *
  * Allocate an ID between 0 and %INT_MAX, inclusive.
  *
- * Context: Any context.
+ * Context: Any context. It is safe to call this function without
+ * locking in your code.
  * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
  * or %-ENOSPC if there are no free IDs.
  */
@@ -280,7 +281,8 @@ static inline int ida_alloc(struct ida *ida, gfp_t gfp)
  *
  * Allocate an ID between @min and %INT_MAX, inclusive.
  *
- * Context: Any context.
+ * Context: Any context. It is safe to call this function without
+ * locking in your code.
  * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
  * or %-ENOSPC if there are no free IDs.
  */
@@ -297,7 +299,8 @@ static inline int ida_alloc_min(struct ida *ida, unsigned int min, gfp_t gfp)
  *
  * Allocate an ID between 0 and @max, inclusive.
  *
- * Context: Any context.
+ * Context: Any context. It is safe to call this function without
+ * locking in your code.
  * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
  * or %-ENOSPC if there are no free IDs.
  */
diff --git a/lib/idr.c b/lib/idr.c
index c2cf2c52bbde..3fa8be43696f 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -372,7 +372,8 @@ EXPORT_SYMBOL(idr_replace);
  * Allocate an ID between @min and @max, inclusive.  The allocated ID will
  * not exceed %INT_MAX, even if @max is larger.
  *
- * Context: Any context.
+ * Context: Any context. It is safe to call this function without
+ * locking in your code.
  * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
  * or %-ENOSPC if there are no free IDs.
  */
@@ -479,7 +480,8 @@ EXPORT_SYMBOL(ida_alloc_range);
  * @ida: IDA handle.
  * @id: Previously allocated ID.
  *
- * Context: Any context.
+ * Context: Any context. It is safe to call this function without
+ * locking in your code.
  */
 void ida_free(struct ida *ida, unsigned int id)
 {
@@ -531,7 +533,8 @@ EXPORT_SYMBOL(ida_free);
  * or freed.  If the IDA is already empty, there is no need to call this
  * function.
  *
- * Context: Any context.
+ * Context: Any context. It is safe to call this function without
+ * locking in your code.
  */
 void ida_destroy(struct ida *ida)
 {

base-commit: d012a7190fc1fd72ed48911e77ca97ba4521bccd
-- 
Sent by a computer, using git, on the internet


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

* [PATCH v3 2/2] idr: Document that ida_simple_{get,remove}() are deprecated
  2020-09-10  5:52 [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks Stephen Boyd
@ 2020-09-10  5:52 ` Stephen Boyd
  2020-09-10 16:19 ` [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2020-09-10  5:52 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Greg KH, Tri Vo, Jonathan Corbet, linux-doc,
	Matthew Wilcox

These two functions are deprecated. Users should call ida_alloc() or
ida_free() respectively instead. Add documentation to this effect until
the macro can be removed.

Cc: Greg KH <gregkh@linuxfoundation.org>
Reviewed-by: Tri Vo <trong@android.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/idr.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/linux/idr.h b/include/linux/idr.h
index b235ed987021..a0dce14090a9 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -314,6 +314,10 @@ static inline void ida_init(struct ida *ida)
 	xa_init_flags(&ida->xa, IDA_INIT_FLAGS);
 }
 
+/*
+ * ida_simple_get() and ida_simple_remove() are deprecated. Use
+ * ida_alloc() and ida_free() instead respectively.
+ */
 #define ida_simple_get(ida, start, end, gfp)	\
 			ida_alloc_range(ida, start, (end) - 1, gfp)
 #define ida_simple_remove(ida, id)	ida_free(ida, id)
-- 
Sent by a computer, using git, on the internet


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

* Re: [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks
  2020-09-10  5:52 [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks Stephen Boyd
  2020-09-10  5:52 ` [PATCH v3 2/2] idr: Document that ida_simple_{get,remove}() are deprecated Stephen Boyd
@ 2020-09-10 16:19 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2020-09-10 16:19 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Tri Vo, Jonathan Corbet, linux-doc,
	Matthew Wilcox

On Wed, Sep 09, 2020 at 10:52:45PM -0700, Stephen Boyd wrote:
> The documentation for these functions indicates that callers don't need
> to hold a lock while calling them, but that documentation is only in one
> place under "IDA Usage". Let's state the same information on each IDA
> function so that it's clear what the calling context requires.
> Furthermore, let's document ida_simple_get() with the same information
> so that callers know how this API works.

Thank you for this, I always have to go look it up too...

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

end of thread, other threads:[~2020-09-10 16:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-10  5:52 [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks Stephen Boyd
2020-09-10  5:52 ` [PATCH v3 2/2] idr: Document that ida_simple_{get,remove}() are deprecated Stephen Boyd
2020-09-10 16:19 ` [PATCH v3 1/2] idr: Document calling context for IDA APIs mustn't use locks Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).