[PATCH] drm/nouveau/gsp: Use kzalloc_flex() for r535 display funcs

Rosen Penev posted 1 patch 3 weeks, 1 day ago
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] drm/nouveau/gsp: Use kzalloc_flex() for r535 display funcs
Posted by Rosen Penev 3 weeks, 1 day ago
struct nvkm_disp_func ends with the user flexible array member. Allocate the
r535 display function table with kzalloc_flex() instead of open-coding the
size calculation with sizeof().

This makes the allocation describe the object being allocated directly and
keeps the fixed six user entries unchanged.

Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
index 6e63df816d85..1155f079b0c3 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
@@ -1734,7 +1734,8 @@ r535_disp_new(const struct nvkm_disp_func *hw, struct nvkm_device *device,
 	struct nvkm_disp_func *rm;
 	int ret;
 
-	if (!(rm = kzalloc(sizeof(*rm) + 6 * sizeof(rm->user[0]), GFP_KERNEL)))
+	rm = kzalloc_flex(*rm, user, 6);
+	if (!rm)
 		return -ENOMEM;
 
 	rm->dtor = r535_disp_dtor;
-- 
2.54.0
Re: [PATCH] drm/nouveau/gsp: Use kzalloc_flex() for r535 display funcs
Posted by lyude@redhat.com 3 weeks ago
Reviewed-by: Lyude Paul <lyude@redhat.com>

There's one change to make below, but I will just handle it locally
before pushing:

On Thu, 2026-05-07 at 22:20 -0700, Rosen Penev wrote:
> struct nvkm_disp_func ends with the user flexible array member.
> Allocate the
> r535 display function table with kzalloc_flex() instead of open-
> coding the
> size calculation with sizeof().
> 
> This makes the allocation describe the object being allocated
> directly and
> keeps the fixed six user entries unchanged.
> 

I assume this was the AI talking, but this sentence seems like a
nothing-burger. Will just drop it from the commit.

> Assisted-by: Codex:GPT-5.5
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
> b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
> index 6e63df816d85..1155f079b0c3 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
> @@ -1734,7 +1734,8 @@ r535_disp_new(const struct nvkm_disp_func *hw,
> struct nvkm_device *device,
>  	struct nvkm_disp_func *rm;
>  	int ret;
>  
> -	if (!(rm = kzalloc(sizeof(*rm) + 6 * sizeof(rm->user[0]),
> GFP_KERNEL)))
> +	rm = kzalloc_flex(*rm, user, 6);
> +	if (!rm)
>  		return -ENOMEM;
>  
>  	rm->dtor = r535_disp_dtor;