Skip to content

Commit e7716c7

Browse files
Philipp StannerMatthew Wilcox (Oracle)
authored andcommitted
xarray: Document necessary flag in alloc functions
Adds a new line to the docstrings of functions wrapping __xa_alloc() and __xa_alloc_cyclic(), informing about the necessity of flag XA_FLAGS_ALLOC being set previously. The documentation so far says that functions wrapping __xa_alloc() and __xa_alloc_cyclic() are supposed to return either -ENOMEM or -EBUSY in case of an error. If the xarray has been initialized without the flag XA_FLAGS_ALLOC, however, they fail with a different, undocumented error code. As hinted at in Documentation/core-api/xarray.rst, wrappers around these functions should only be invoked when the flag has been set. The functions' documentation should reflect that as well. Signed-off-by: Philipp Stanner <pstanner@redhat.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
1 parent cbc0285 commit e7716c7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

include/linux/xarray.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,9 @@ static inline int __must_check xa_insert_irq(struct xarray *xa,
856856
* stores the index into the @id pointer, then stores the entry at
857857
* that index. A concurrent lookup will not see an uninitialised @id.
858858
*
859+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
860+
* in xa_init_flags().
861+
*
859862
* Context: Any context. Takes and releases the xa_lock. May sleep if
860863
* the @gfp flags permit.
861864
* Return: 0 on success, -ENOMEM if memory could not be allocated or
@@ -886,6 +889,9 @@ static inline __must_check int xa_alloc(struct xarray *xa, u32 *id,
886889
* stores the index into the @id pointer, then stores the entry at
887890
* that index. A concurrent lookup will not see an uninitialised @id.
888891
*
892+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
893+
* in xa_init_flags().
894+
*
889895
* Context: Any context. Takes and releases the xa_lock while
890896
* disabling softirqs. May sleep if the @gfp flags permit.
891897
* Return: 0 on success, -ENOMEM if memory could not be allocated or
@@ -916,6 +922,9 @@ static inline int __must_check xa_alloc_bh(struct xarray *xa, u32 *id,
916922
* stores the index into the @id pointer, then stores the entry at
917923
* that index. A concurrent lookup will not see an uninitialised @id.
918924
*
925+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
926+
* in xa_init_flags().
927+
*
919928
* Context: Process context. Takes and releases the xa_lock while
920929
* disabling interrupts. May sleep if the @gfp flags permit.
921930
* Return: 0 on success, -ENOMEM if memory could not be allocated or
@@ -949,6 +958,9 @@ static inline int __must_check xa_alloc_irq(struct xarray *xa, u32 *id,
949958
* The search for an empty entry will start at @next and will wrap
950959
* around if necessary.
951960
*
961+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
962+
* in xa_init_flags().
963+
*
952964
* Context: Any context. Takes and releases the xa_lock. May sleep if
953965
* the @gfp flags permit.
954966
* Return: 0 if the allocation succeeded without wrapping. 1 if the
@@ -983,6 +995,9 @@ static inline int xa_alloc_cyclic(struct xarray *xa, u32 *id, void *entry,
983995
* The search for an empty entry will start at @next and will wrap
984996
* around if necessary.
985997
*
998+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
999+
* in xa_init_flags().
1000+
*
9861001
* Context: Any context. Takes and releases the xa_lock while
9871002
* disabling softirqs. May sleep if the @gfp flags permit.
9881003
* Return: 0 if the allocation succeeded without wrapping. 1 if the
@@ -1017,6 +1032,9 @@ static inline int xa_alloc_cyclic_bh(struct xarray *xa, u32 *id, void *entry,
10171032
* The search for an empty entry will start at @next and will wrap
10181033
* around if necessary.
10191034
*
1035+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
1036+
* in xa_init_flags().
1037+
*
10201038
* Context: Process context. Takes and releases the xa_lock while
10211039
* disabling interrupts. May sleep if the @gfp flags permit.
10221040
* Return: 0 if the allocation succeeded without wrapping. 1 if the

lib/xarray.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,9 @@ EXPORT_SYMBOL(xa_get_order);
18021802
* stores the index into the @id pointer, then stores the entry at
18031803
* that index. A concurrent lookup will not see an uninitialised @id.
18041804
*
1805+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
1806+
* in xa_init_flags().
1807+
*
18051808
* Context: Any context. Expects xa_lock to be held on entry. May
18061809
* release and reacquire xa_lock if @gfp flags permit.
18071810
* Return: 0 on success, -ENOMEM if memory could not be allocated or
@@ -1850,6 +1853,9 @@ EXPORT_SYMBOL(__xa_alloc);
18501853
* The search for an empty entry will start at @next and will wrap
18511854
* around if necessary.
18521855
*
1856+
* Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set
1857+
* in xa_init_flags().
1858+
*
18531859
* Context: Any context. Expects xa_lock to be held on entry. May
18541860
* release and reacquire xa_lock if @gfp flags permit.
18551861
* Return: 0 if the allocation succeeded without wrapping. 1 if the

0 commit comments

Comments
 (0)