Skip to contentSkip to conversation

drm/amdkfd: fix loop error handling

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

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

PATCH 1/1 drm/amdkfd: fix loop error handling

From: Tom Rix <[email protected]>

Clang static analysis reports this problem kfd_chardev.c:2594:16: warning: The expression is an uninitialized value.
The computed value will also be garbage

        while (ret && i--) {
                      ^~~

i is a loop variable and this block unwinds a problem in the loop. When the error happens before the loop, this value is garbage. Move the initialization of i to its decalaration.

Fixes be072b06c739 ("drm/amdkfd: CRIU export BOs as prime dmabuf objects")
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -2
index 636391c61cafb..4310ca07af130 100644
@@ -2374,7 +2374,7 @@ static int criu_restore_bos(struct kfd_process *p,
 	const bool criu_resume = true;
 	bool flush_tlbs = false;
 	int ret = 0, j = 0;
-	uint32_t i;
+	uint32_t i = 0;
 
 	if (*priv_offset + (args->num_bos * sizeof(*bo_privs)) > max_priv_data_size)
 		return -EINVAL;
@@ -2410,7 +2410,7 @@ static int criu_restore_bos(struct kfd_process *p,
 	*priv_offset += args->num_bos * sizeof(*bo_privs);
 
 	/* Create and map new BOs */
-	for (i = 0; i < args->num_bos; i++) {
+	for (; i < args->num_bos; i++) {
 		struct kfd_criu_bo_bucket *bo_bucket;
 		struct kfd_criu_bo_priv_data *bo_priv;
 		struct kfd_dev *dev;
Signature · 1 line
2.26.3
maintainer
#1 lore raw

Am 2022-02-10 um 12:04 schrieb [email protected]:

Quoted 8 lines

From: Tom Rix <[email protected]>

Clang static analysis reports this problem kfd_chardev.c:2594:16: warning: The expression is an uninitialized value.
The computed value will also be garbage

         while (ret && i--) {
                       ^~~
Quoted 6 lines

i is a loop variable and this block unwinds a problem in the loop. When the error happens before the loop, this value is garbage. Move the initialization of i to its decalaration.

Fixes be072b06c739 ("drm/amdkfd: CRIU export BOs as prime dmabuf objects")

Thank you. I applied the patch to amd-staging-drm-next.

Regards,
  Felix

Quoted 26 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -2
index 636391c61cafb..4310ca07af130 100644
@@ -2374,7 +2374,7 @@ static int criu_restore_bos(struct kfd_process *p,
  	const bool criu_resume = true;
  	bool flush_tlbs = false;
  	int ret = 0, j = 0;
-	uint32_t i;
+	uint32_t i = 0;
 
  	if (*priv_offset + (args->num_bos * sizeof(*bo_privs)) > max_priv_data_size)
  		return -EINVAL;
@@ -2410,7 +2410,7 @@ static int criu_restore_bos(struct kfd_process *p,
  	*priv_offset += args->num_bos * sizeof(*bo_privs);
 
  	/* Create and map new BOs */
-	for (i = 0; i < args->num_bos; i++) {
+	for (; i < args->num_bos; i++) {
  		struct kfd_criu_bo_bucket *bo_bucket;
  		struct kfd_criu_bo_priv_data *bo_priv;
  		struct kfd_dev *dev;