drm/vc4_validate: Remove VLA usage
Subsystems (3)
PATCH 1/1 drm/vc4_validate: Remove VLA usage
In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _bo_ can be computed at preprocessing time.
The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
--- drivers/gpu/drm/vc4/vc4_validate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_validate.c +1 -1
@@ -753,7 +753,7 @@ validate_gl_shader_rec(struct drm_device *dev, 28, /* cs */ };uint32_t shader_reloc_count =ARRAY_SIZE (shader_reloc_offsets); -struct drm_gem_cma_object *bo[shader_reloc_count +8 ]; +struct drm_gem_cma_object *bo[ARRAY_SIZE (shader_reloc_offsets) +8 ];uint32_t nr_attributes, nr_relocs, packet_size;int i;
Signature · 1 line
2.7.4
Quoted 33 lines · Gustavo A. R. Silva
In preparation to enabling -Wvla, remove VLA. In this particular case use macro
ARRAY_SIZEso the length of array _bo_ can be computed at preprocessing time.The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/gpu/drm/vc4/vc4_validate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_validate.c +1
-1@@ -753,7 +753,7 @@ validate_gl_shader_rec(struct drm_device *dev, 28, /* cs */ };uint32_t shader_reloc_count =ARRAY_SIZE (shader_reloc_offsets); -struct drm_gem_cma_object *bo[shader_reloc_count +8 ]; +struct drm_gem_cma_object *bo[ARRAY_SIZE (shader_reloc_offsets) +8 ];uint32_t nr_attributes, nr_relocs, packet_size;int i;Signature · 1 line
2.7.4
It's a shame that the compiler is warning about this when it's obviously a compile-time constant. Regardless, reviewed and applied.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel