Re: [PATCH 20/20] selftests/vfio: Fix VLA initialisation in vfio_pci_irq_set()
From: Dave Jiang
Date: Fri Mar 13 2026 - 18:24:03 EST
On 3/11/26 1:34 PM, mhonap@xxxxxxxxxx wrote:
> From: Manish Honap <mhonap@xxxxxxxxxx>
>
> C does not permit initialiser expressions on variable-length arrays.
> vfio_pci_irq_set() declared
>
> u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
>
> where count is a function parameter, making buf a VLA. GCC rejects
> this with "variable-sized object may not be initialized".
>
> Replace the initialiser with an explicit memset() immediately after
> the declaration.
>
> Fixes: 19faf6fd969c2 ("vfio: selftests: Add a helper library for VFIO selftests")
Should this fix be split out from the series and sent ahead? Does not seem to be tied to the current implementation.
DJ
> Signed-off-by: Manish Honap <mhonap@xxxxxxxxxx>
> ---
> tools/testing/selftests/vfio/lib/vfio_pci_device.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> index fac4c0ecadef..3258e814f450 100644
> --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> @@ -26,8 +26,10 @@
> static void vfio_pci_irq_set(struct vfio_pci_device *device,
> u32 index, u32 vector, u32 count, int *fds)
> {
> - u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
> + u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count];
> struct vfio_irq_set *irq = (void *)&buf;
> +
> + memset(buf, 0, sizeof(buf));
> int *irq_fds = (void *)&irq->data;
>
> irq->argsz = sizeof(buf);