Skip to contentSkip to conversation

xarray: Fix lock/unlock imbalance in xa_alloc

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Jul 6, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xarray: Fix lock/unlock imbalance in xa_alloc

Release *xa_lock* before return.

Addresses-Coverity-ID: 1471631 ("Missing unlock")

Fixes 29a6bfc32eb2 ("xarray: Track free entries in an XArray")
---
 lib/xarray.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/xarray.c +3 -1
index be10039..a27fdb38 100644
@@ -1474,8 +1474,10 @@ int xa_alloc(struct xarray *xa, u32 *id, void *entry, gfp_t gfp)
 		xas.xa_index = 0;
 		xas_lock(&xas);
 		xas_find_tagged(&xas, UINT_MAX, XA_FREE_TAG);
-		if (xas.xa_node == XAS_BOUNDS && xas.xa_index == UINT_MAX + 1)
+		if (xas.xa_node == XAS_BOUNDS && xas.xa_index == UINT_MAX + 1) {
+			xas_unlock(&xas);
 			return -ENOSPC;
+		}
 		*id = xas.xa_index;
 		xas_store(&xas, entry);
 		xas_clear_tag(&xas, XA_FREE_TAG);
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 1 line · Gustavo A. R. Silva

Release *xa_lock* before return.

Thank you! I need to improve the test suite to catch that one.

#2 lore raw
Quoted 5 lines · Matthew Wilcox
Quoted 1 line · Gustavo A. R. Silva

Release *xa_lock* before return.

Thank you! I need to improve the test suite to catch that one.

Glad to help. :)

Thanks
--
Gustavo