mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 13:41:30 +00:00
XArray: Handle NULL pointers differently for allocation
For allocating XArrays, it makes sense to distinguish beteen erasing an entry and storing NULL. Storing NULL keeps the index allocated with a NULL pointer associated with it while xa_erase() frees the index. Some existing IDR users rely on this ability. Signed-off-by: Matthew Wilcox <willy@infradead.org>
This commit is contained in:
parent
611f318637
commit
d9c480435a
2 changed files with 29 additions and 12 deletions
13
lib/xarray.c
13
lib/xarray.c
|
@ -1382,10 +1382,12 @@ void *__xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
|
|||
|
||||
if (WARN_ON_ONCE(xa_is_internal(entry)))
|
||||
return XA_ERROR(-EINVAL);
|
||||
if (xa_track_free(xa) && !entry)
|
||||
entry = XA_ZERO_ENTRY;
|
||||
|
||||
do {
|
||||
curr = xas_store(&xas, entry);
|
||||
if (xa_track_free(xa) && entry)
|
||||
if (xa_track_free(xa))
|
||||
xas_clear_mark(&xas, XA_FREE_MARK);
|
||||
} while (__xas_nomem(&xas, gfp));
|
||||
|
||||
|
@ -1446,6 +1448,8 @@ void *__xa_cmpxchg(struct xarray *xa, unsigned long index,
|
|||
|
||||
if (WARN_ON_ONCE(xa_is_internal(entry)))
|
||||
return XA_ERROR(-EINVAL);
|
||||
if (xa_track_free(xa) && !entry)
|
||||
entry = XA_ZERO_ENTRY;
|
||||
|
||||
do {
|
||||
curr = xas_load(&xas);
|
||||
|
@ -1453,7 +1457,7 @@ void *__xa_cmpxchg(struct xarray *xa, unsigned long index,
|
|||
curr = NULL;
|
||||
if (curr == old) {
|
||||
xas_store(&xas, entry);
|
||||
if (xa_track_free(xa) && entry)
|
||||
if (xa_track_free(xa))
|
||||
xas_clear_mark(&xas, XA_FREE_MARK);
|
||||
}
|
||||
} while (__xas_nomem(&xas, gfp));
|
||||
|
@ -1487,8 +1491,11 @@ int __xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp)
|
|||
|
||||
do {
|
||||
curr = xas_load(&xas);
|
||||
if (!curr)
|
||||
if (!curr) {
|
||||
xas_store(&xas, XA_ZERO_ENTRY);
|
||||
if (xa_track_free(xa))
|
||||
xas_clear_mark(&xas, XA_FREE_MARK);
|
||||
}
|
||||
} while (__xas_nomem(&xas, gfp));
|
||||
|
||||
return xas_error(&xas);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue