Skip to contentSkip to conversation

drm/amdkfd: fix freeing an unset pointer

PATCH In review [email protected] 2 participants 2 messages Feb 9, 2022

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

PATCH 1/1 drm/amdkfd: fix freeing an unset pointer

From: Tom Rix <[email protected]>

clang static analysis reports this problem kfd_chardev.c:2092:2: warning: 1st function call argument
is an uninitialized value

        kvfree(bo_privs);
        ^~~~~~~~~~~~~~~~

When bo_buckets alloc fails, it jumps to an error handler that frees the yet to be allocated bo_privs. Because bo_buckets is the first error, return directly.

Fixes 5ccbb057c0a1 ("drm/amdkfd: CRIU Implement KFD checkpoint ioctl")
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -4
index 64e3b4e3a7126..636391c61cafb 100644
@@ -1982,10 +1982,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
 	void *mem;
 
 	bo_buckets = kvzalloc(num_bos * sizeof(*bo_buckets), GFP_KERNEL);
-	if (!bo_buckets) {
-		ret = -ENOMEM;
-		goto exit;
-	}
+	if (!bo_buckets)
+		return -ENOMEM;
 
 	bo_privs = kvzalloc(num_bos * sizeof(*bo_privs), GFP_KERNEL);
 	if (!bo_privs) {
Signature · 1 line
2.26.3
maintainer
#1 lore raw
Quoted 5 lines · On 2022-02-09 09:52, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analysis reports this problem kfd_chardev.c:2092:2: warning: 1st function call argument
is an uninitialized value

Quoted 8 lines
         kvfree(bo_privs);
         ^~~~~~~~~~~~~~~~

When bo_buckets alloc fails, it jumps to an error handler that frees the yet to be allocated bo_privs. Because bo_buckets is the first error, return directly.

Fixes 5ccbb057c0a1 ("drm/amdkfd: CRIU Implement KFD checkpoint ioctl")

Thank you, Tom. I'm applying your patch to amd-staging-drm-next.

Regards,
  Felix

Quoted 23 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -4
index 64e3b4e3a7126..636391c61cafb 100644
@@ -1982,10 +1982,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
  	void *mem;
 
  	bo_buckets = kvzalloc(num_bos * sizeof(*bo_buckets), GFP_KERNEL);
-	if (!bo_buckets) {
-		ret = -ENOMEM;
-		goto exit;
-	}
+	if (!bo_buckets)
+		return -ENOMEM;
 
  	bo_privs = kvzalloc(num_bos * sizeof(*bo_privs), GFP_KERNEL);
  	if (!bo_privs) {