diff mbox

xarray: Fix lock/unlock imbalance in xa_alloc

Message ID 20180706131044.GA25469@embeddedor.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gustavo A. R. Silva July 6, 2018, 1:10 p.m. UTC
Release *xa_lock* before return.

Addresses-Coverity-ID: 1471631 ("Missing unlock")
Fixes: 29a6bfc32eb2 ("xarray: Track free entries in an XArray")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 lib/xarray.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Matthew Wilcox July 6, 2018, 2:11 p.m. UTC | #1
On Fri, Jul 06, 2018 at 08:10:44AM -0500, Gustavo A. R. Silva wrote:
> Release *xa_lock* before return.

Thank you!  I need to improve the test suite to catch that one.
Gustavo A. R. Silva July 6, 2018, 2:13 p.m. UTC | #2
On 07/06/2018 09:11 AM, Matthew Wilcox wrote:
> On Fri, Jul 06, 2018 at 08:10:44AM -0500, Gustavo A. R. Silva wrote:
>> Release *xa_lock* before return.
> 
> Thank you!  I need to improve the test suite to catch that one.
> 

Glad to help. :)

Thanks
--
Gustavo
diff mbox

Patch

diff --git a/lib/xarray.c b/lib/xarray.c
index be10039..a27fdb38 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -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);