diff options
author | Matthew Wilcox <mawilcox@microsoft.com> | 2017-11-28 10:14:27 -0500 |
---|---|---|
committer | Matthew Wilcox <mawilcox@microsoft.com> | 2018-02-06 16:40:32 -0500 |
commit | e096f6a762bc54d0e5d44ba8b196e70b58e04367 (patch) | |
tree | 7565cca4a67e46001abbf0125501acf4e39a4a3c /include/linux/idr.h | |
parent | 322d884ba731e05ca79ae58e9dee1ef7dc4de504 (diff) | |
download | lwn-e096f6a762bc54d0e5d44ba8b196e70b58e04367.tar.gz lwn-e096f6a762bc54d0e5d44ba8b196e70b58e04367.zip |
idr: Add idr_alloc_u32 helper
All current users of idr_alloc_ext() actually want to allocate a u32
and idr_alloc_u32() fits their needs better.
Like idr_get_next(), it uses a 'nextid' argument which serves as both
a pointer to the start ID and the assigned ID (instead of a separate
minimum and pointer-to-assigned-ID argument). It uses a 'max' argument
rather than 'end' because the semantics that idr_alloc has for 'end'
don't work well for unsigned types.
Since idr_alloc_u32() returns an errno instead of the allocated ID, mark
it as __must_check to help callers use it correctly. Include copious
kernel-doc. Chris Mi <chrism@mellanox.com> has promised to contribute
test-cases for idr_alloc_u32.
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Diffstat (limited to 'include/linux/idr.h')
-rw-r--r-- | include/linux/idr.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h index 7867d6117535..561a4cbabca6 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -131,6 +131,8 @@ static inline int idr_alloc_ext(struct idr *idr, void *ptr, return idr_alloc_cmn(idr, ptr, index, start, end, gfp, true); } +int __must_check idr_alloc_u32(struct idr *, void *ptr, u32 *nextid, + unsigned long max, gfp_t); int idr_alloc_cyclic(struct idr *, void *entry, int start, int end, gfp_t); int idr_for_each(const struct idr *, int (*fn)(int id, void *p, void *data), void *data); |