[PATCH] drm/amdgpu/atom: Check kcalloc() for WS buffer in amdgpu_atom_execute_table_locked()

Guangshuo Li posted 1 patch 1 week, 6 days ago
There is a newer version of this series
drivers/gpu/drm/amd/amdgpu/atom.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] drm/amdgpu/atom: Check kcalloc() for WS buffer in amdgpu_atom_execute_table_locked()
Posted by Guangshuo Li 1 week, 6 days ago
kcalloc() may fail. When WS is non-zero and allocation fails, ectx.ws
remains NULL while ectx.ws_size is set, leading to a potential NULL
pointer dereference in atom_get_src_int() when accessing WS entries.

Return -ENOMEM on allocation failure to avoid the NULL dereference.

Fixes: 6396bb221514 ("treewide: kzalloc() -> kcalloc()")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/atom.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/atom.c b/drivers/gpu/drm/amd/amdgpu/atom.c
index 82a02f831951..bed3083f317b 100644
--- a/drivers/gpu/drm/amd/amdgpu/atom.c
+++ b/drivers/gpu/drm/amd/amdgpu/atom.c
@@ -1247,9 +1247,9 @@ static int amdgpu_atom_execute_table_locked(struct atom_context *ctx, int index,
 	if (ws) {
 		ectx.ws = kcalloc(4, ws, GFP_KERNEL);
 		if (!ectx.ws) {
-        	ret = -ENOMEM;
-        	goto free;
-        }
+			ret = -ENOMEM;
+			goto free;
+		}
 		ectx.ws_size = ws;
 	} else {
 		ectx.ws = NULL;
-- 
2.43.0
Re: [PATCH] drm/amdgpu/atom: Check kcalloc() for WS buffer in amdgpu_atom_execute_table_locked()
Posted by Alex Deucher 1 week, 6 days ago
On Thu, Sep 18, 2025 at 8:44 AM Guangshuo Li <lgs201920130244@gmail.com> wrote:
>
> kcalloc() may fail. When WS is non-zero and allocation fails, ectx.ws
> remains NULL while ectx.ws_size is set, leading to a potential NULL
> pointer dereference in atom_get_src_int() when accessing WS entries.
>
> Return -ENOMEM on allocation failure to avoid the NULL dereference.
>
> Fixes: 6396bb221514 ("treewide: kzalloc() -> kcalloc()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/atom.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/atom.c b/drivers/gpu/drm/amd/amdgpu/atom.c
> index 82a02f831951..bed3083f317b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/atom.c
> +++ b/drivers/gpu/drm/amd/amdgpu/atom.c
> @@ -1247,9 +1247,9 @@ static int amdgpu_atom_execute_table_locked(struct atom_context *ctx, int index,
>         if (ws) {
>                 ectx.ws = kcalloc(4, ws, GFP_KERNEL);
>                 if (!ectx.ws) {
> -               ret = -ENOMEM;
> -               goto free;
> -        }
> +                       ret = -ENOMEM;
> +                       goto free;
> +               }

What branch is this patch against?  This doesn't apply as is.  I've
fixed this up manually and applied it.

Thanks,

Alex

>                 ectx.ws_size = ws;
>         } else {
>                 ectx.ws = NULL;
> --
> 2.43.0
>