Re: [PATCH] drm/amdgpu: replace 1-element arrays with flexible arrays
From: Gustavo A. R. Silva
Date: Fri Jul 14 2023 - 14:13:58 EST
On 7/12/23 08:12, Alex Deucher wrote:
On Wed, Jul 12, 2023 at 8:04 AM Ricardo Cañuelo
<ricardo.canuelo@xxxxxxxxxxxxx> wrote:
UBSAN complains about out-of-bounds array indexes on all 1-element
arrays defined on this driver:
UBSAN: array-index-out-of-bounds in /home/rcn/work/repos/kernelci/kernelci-core/linux_kernel_mainline/drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/processpptables.c:1249:61
Substitute them with proper flexible arrays.
+ Gustavo, Paulo
I haven't kept up with the flexible arrays stuff. Is this equivalent
to a zero sized array? We've been bitten by these kind of changes in
In terms of size, yes: the size of each array declaration does not
contribute to the overall size of its containing structure.
However, in these cases, using the DECLARE_FLEX_ARRAY() helper is not
required. Simply removing the '1' from the array declaration will suffice.
This helper was created to declare flex-array members in unions, as well
as in structs that contain no other members aside from the array.
In any case, these changes are not complete, as they're only modifying
the struct declaration, hence the size of the struct is affected. Now
the rest of the code where these structs are involved should be audited
and adjusted to accommodate the change in the sizes of the structs.
the past. These structures define the layout of data in a rom image
on the board. If the struct size changes, that could lead to errors
in the code that deals with these structures.
Alex
Thanks
--
Gustavo