amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
Subsystems (2)
PATCH 1/1 amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
Make use of the new struct_size() helper instead of the offsetof() idiom. Also, use kmalloc() instead of kcalloc().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -1
@@ -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),GFP_KERNEL );if (!entity)return -ENOMEM ;
Signature · 1 line
2.27.0
Alex Deucher
AppliedApplied. Thanks!
Alex
Quoted 29 lines · Gustavo A. R. Silva
Make use of the new
struct_size()helper instead of theoffsetof()idiom. Also, usekmalloc()instead ofkcalloc().Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1
-2@@ -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),GFP_KERNEL );if (!entity)return -ENOMEM ; --2.27.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 08.10.20 um 16:34 schrieb Gustavo A. R. Silva:
Quoted 13 lines
Make use of the new
struct_size()helper instead of theoffsetof()idiom. Also, usekmalloc()instead ofkcalloc().Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip, · line 103
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1
-1@@ -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.
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0GFP_KERNEL);if (!entity)return -ENOMEM ;
Quoted 9 lines · Christian König
Am 08.10.20 um 16:34 schrieb Gustavo A. R. Silva:
Quoted 8 lines
Make use of the new
struct_size()helper instead of theoffsetof()idiom. Also, usekmalloc()instead ofkcalloc().Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip, · line 102
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1
-1@@ -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
Christian König
maintainerAm 09.10.20 um 15:54 schrieb Gustavo A. R. Silva:
Quoted 21 lines · Christian König
Quoted 9 lines
Am 08.10.20 um 16:34 schrieb Gustavo A. R. Silva:
Quoted 8 lines
Make use of the new
struct_size()helper instead of theoffsetof()idiom. Also, usekmalloc()instead ofkcalloc().Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip, · line 102
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1
-1@@ -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.
Quoted 3 lines
Oh I see.. I certainly didn't take that into account.
I'll fix that up and respin.
Shit happens, we already have a fix for this. Alex merged it and it immediately broke our testing systems.
So one of our engineers came up with a fix which should already have been applied.
Christian.
Quoted 4 lines
Thanks
--
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 10 lines · Christian König
Quoted 7 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip, · line 103
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1
-1- 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.
Shit happens, we already have a fix for this. Alex merged it and it immediately broke our testing systems.
:/
Quoted 2 lines
So one of our engineers came up with a fix which should already have been applied.
Great. Good to know it's already fixed! :)
Thanks
--
Gustavo
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx