dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amdkfd: fix loop error handling
@ 2022-02-10 17:04 trix
  2022-02-10 19:17 ` Felix Kuehling
  0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2022-02-10 17:04 UTC (permalink / raw)
  To: Felix.Kuehling, alexander.deucher, christian.koenig, Xinhui.Pan,
	airlied, daniel, nathan, ndesaulniers, rajneesh.bhardwaj,
	david.yatsin
  Cc: Tom Rix, llvm, dri-devel, amd-gfx, linux-kernel

From: Tom Rix <trix@redhat.com>

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")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 636391c61cafb..4310ca07af130 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -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;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdkfd: fix loop error handling
  2022-02-10 17:04 [PATCH] drm/amdkfd: fix loop error handling trix
@ 2022-02-10 19:17 ` Felix Kuehling
  0 siblings, 0 replies; 2+ messages in thread
From: Felix Kuehling @ 2022-02-10 19:17 UTC (permalink / raw)
  To: trix, alexander.deucher, christian.koenig, Xinhui.Pan, airlied,
	daniel, nathan, ndesaulniers, rajneesh.bhardwaj, david.yatsin
  Cc: llvm, amd-gfx, dri-devel, linux-kernel

Am 2022-02-10 um 12:04 schrieb trix@redhat.com:
> From: Tom Rix <trix@redhat.com>
>
> 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")
> Signed-off-by: Tom Rix <trix@redhat.com>

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

Regards,
   Felix


> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 636391c61cafb..4310ca07af130 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-10 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 17:04 [PATCH] drm/amdkfd: fix loop error handling trix
2022-02-10 19:17 ` Felix Kuehling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).