ocxl: Fix potential memory leak on context creation
Subsystems (2)
PATCH 1/1 ocxl: Fix potential memory leak on context creation
If we couldn't fully init a context, we were leaking memory.
--- drivers/misc/ocxl/context.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/ocxl/context.c +1 -0
@@ -22,6 +22,7 @@ int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, afu->pasid_base + afu->pasid_max, GFP_KERNEL);if (pasid <0 ) {mutex_unlock (&afu->contexts_lock); +kfree (*context);return pasid; } afu->pasid_count++;
Signature · 1 line
2.21.0
Quoted 4 lines · Frederic Barrat
If we couldn't fully init a context, we were leaking memory.
Fixes b9721d275cc2 ("ocxl: Allow external drivers to use OpenCAPI contexts")Signed-off-by Frederic Barrat <[email protected]>
drivers/misc/ocxl/context.c int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, · line 25
Quoted 13 lines
--- drivers/misc/ocxl/context.c | 1 + 1 file changed, 1 insertion(+)drivers/misc/ocxl/context.c +1
-0@@ -22,6 +22,7 @@ int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, afu->pasid_base + afu->pasid_max, GFP_KERNEL);if (pasid <0 ) {mutex_unlock (&afu->contexts_lock); +kfree (*context);
(defensive programming: set *context = NULL so that if the caller ignores the return code we get an obvious crash)
Quoted 4 lines
drivers/misc/ocxl/context.c +0
-0return pasid; } afu->pasid_count++;
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Le 20/05/2019 à 03:45, Andrew Donnellan a écrit :
Quoted 12 lines · Frederic Barrat
Quoted 4 lines
If we couldn't fully init a context, we were leaking memory.
Fixes b9721d275cc2 ("ocxl: Allow external drivers to use OpenCAPI contexts")Signed-off-by Frederic Barrat <[email protected]>Acked-by Andrew Donnellan <[email protected]>Quoted 4 lines
---
drivers/misc/ocxl/context.c| 1 +1 file changed, 1 insertion(+)
Quoted 12 lines
drivers/misc/ocxl/context.c int ocxl_context_alloc(struct ocxl_context · line 26
Quoted 10 lines
drivers/misc/ocxl/context.c +1
-0@@ -22,6 +22,7 @@ int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, afu->pasid_base + afu->pasid_max, GFP_KERNEL); if (pasid < 0) { mutex_unlock(&afu->contexts_lock); + kfree(*context);(defensive programming: set *context = NULL so that if the caller ignores the return code we get an obvious crash)
Good point. v2 on its way
Quoted 5 lines
Quoted 4 lines
drivers/misc/ocxl/context.c +0
-0return pasid; }afu->pasid_count++;