From: Alastair D'Silva <alastair@xxxxxxxxxxx> ocxl_context_detach_all() is called from ocxl_function_close(), so there is no reason to leave the contexts allocated, as the caller can do nothing useful with them at that point. This also has the side-effect of freeing any allocated IRQs within the context. Signed-off-by: Alastair D'Silva <alastair@xxxxxxxxxxx> --- drivers/misc/ocxl/context.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/misc/ocxl/context.c b/drivers/misc/ocxl/context.c index 994563a078eb..6cb36ef96e09 100644 --- a/drivers/misc/ocxl/context.c +++ b/drivers/misc/ocxl/context.c @@ -259,10 +259,11 @@ void ocxl_context_detach_all(struct ocxl_afu *afu) { struct ocxl_context *ctx; int tmp; + int rc; mutex_lock(&afu->contexts_lock); idr_for_each_entry(&afu->contexts_idr, ctx, tmp) { - ocxl_context_detach(ctx); + rc = ocxl_context_detach(ctx); /* * We are force detaching - remove any active mmio * mappings so userspace cannot interfere with the @@ -274,6 +275,9 @@ void ocxl_context_detach_all(struct ocxl_afu *afu) if (ctx->mapping) unmap_mapping_range(ctx->mapping, 0, 0, 1); mutex_unlock(&ctx->mapping_lock); + + if (rc != -EBUSY) + ocxl_context_free(ctx); } mutex_unlock(&afu->contexts_lock); } -- 2.23.0