[PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc()

Gustavo A. R. Silva gustavoars at kernel.org
Fri Oct 9 13:54:30 UTC 2020


On Fri, Oct 09, 2020 at 09:08:51AM +0200, Christian König wrote:
> Am 08.10.20 um 16:34 schrieb Gustavo A. R. Silva:
> > Make use of the new struct_size() helper instead of the offsetof() idiom.
> > Also, use kmalloc() instead of kcalloc().
> > 
> > Signed-off-by: Gustavo A. R. Silva <gustavoars at kernel.org>
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> > index c80d8339f58c..5be125f3b92a 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> > @@ -100,7 +100,7 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
> >   	enum drm_sched_priority priority;
> >   	int r;
> > -	entity = kcalloc(1, offsetof(typeof(*entity), fences[amdgpu_sched_jobs]),
> > +	entity = kmalloc(struct_size(entity, fences, amdgpu_sched_jobs),
> 
> NAK. You could use kzalloc() here, but kmalloc won't zero initialize the
> memory which could result in unforeseen consequences.

Oh I see.. I certainly didn't take that into account.

I'll fix that up and respin.

Thanks
--
Gustavo


More information about the amd-gfx mailing list