Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Philipp Stanner and committed by
Matthew Wilcox (Oracle)
e7716c74 cbc02854

+24
+18
include/linux/xarray.h
··· 856 856 * stores the index into the @id pointer, then stores the entry at 857 857 * that index. A concurrent lookup will not see an uninitialised @id. 858 858 * 859 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 860 + * in xa_init_flags(). 861 + * 859 862 * Context: Any context. Takes and releases the xa_lock. May sleep if 860 863 * the @gfp flags permit. 861 864 * Return: 0 on success, -ENOMEM if memory could not be allocated or ··· 889 886 * stores the index into the @id pointer, then stores the entry at 890 887 * that index. A concurrent lookup will not see an uninitialised @id. 891 888 * 889 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 890 + * in xa_init_flags(). 891 + * 892 892 * Context: Any context. Takes and releases the xa_lock while 893 893 * disabling softirqs. May sleep if the @gfp flags permit. 894 894 * Return: 0 on success, -ENOMEM if memory could not be allocated or ··· 921 915 * Finds an empty entry in @xa between @limit.min and @limit.max, 922 916 * stores the index into the @id pointer, then stores the entry at 923 917 * that index. A concurrent lookup will not see an uninitialised @id. 918 + * 919 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 920 + * in xa_init_flags(). 924 921 * 925 922 * Context: Process context. Takes and releases the xa_lock while 926 923 * disabling interrupts. May sleep if the @gfp flags permit. ··· 957 948 * that index. A concurrent lookup will not see an uninitialised @id. 958 949 * The search for an empty entry will start at @next and will wrap 959 950 * around if necessary. 951 + * 952 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 953 + * in xa_init_flags(). 960 954 * 961 955 * Context: Any context. Takes and releases the xa_lock. May sleep if 962 956 * the @gfp flags permit. ··· 995 983 * The search for an empty entry will start at @next and will wrap 996 984 * around if necessary. 997 985 * 986 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 987 + * in xa_init_flags(). 988 + * 998 989 * Context: Any context. Takes and releases the xa_lock while 999 990 * disabling softirqs. May sleep if the @gfp flags permit. 1000 991 * Return: 0 if the allocation succeeded without wrapping. 1 if the ··· 1031 1016 * that index. A concurrent lookup will not see an uninitialised @id. 1032 1017 * The search for an empty entry will start at @next and will wrap 1033 1018 * around if necessary. 1019 + * 1020 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 1021 + * in xa_init_flags(). 1034 1022 * 1035 1023 * Context: Process context. Takes and releases the xa_lock while 1036 1024 * disabling interrupts. May sleep if the @gfp flags permit.
+6
lib/xarray.c
··· 1802 1802 * stores the index into the @id pointer, then stores the entry at 1803 1803 * that index. A concurrent lookup will not see an uninitialised @id. 1804 1804 * 1805 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 1806 + * in xa_init_flags(). 1807 + * 1805 1808 * Context: Any context. Expects xa_lock to be held on entry. May 1806 1809 * release and reacquire xa_lock if @gfp flags permit. 1807 1810 * Return: 0 on success, -ENOMEM if memory could not be allocated or ··· 1852 1849 * that index. A concurrent lookup will not see an uninitialised @id. 1853 1850 * The search for an empty entry will start at @next and will wrap 1854 1851 * around if necessary. 1852 + * 1853 + * Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set 1854 + * in xa_init_flags(). 1855 1855 * 1856 1856 * Context: Any context. Expects xa_lock to be held on entry. May 1857 1857 * release and reacquire xa_lock if @gfp flags permit.