RE: [PATCH 20/20] selftests/vfio: Fix VLA initialisation in vfio_pci_irq_set()
From: Manish Honap
Date: Wed Mar 18 2026 - 14:07:31 EST
> -----Original Message-----
> From: Dave Jiang <dave.jiang@xxxxxxxxx>
> Sent: 14 March 2026 03:54
> To: Manish Honap <mhonap@xxxxxxxxxx>; Aniket Agashe <aniketa@xxxxxxxxxx>;
> Ankit Agrawal <ankita@xxxxxxxxxx>; Alex Williamson
> <alwilliamson@xxxxxxxxxx>; Vikram Sethi <vsethi@xxxxxxxxxx>; Jason
> Gunthorpe <jgg@xxxxxxxxxx>; Matt Ochs <mochs@xxxxxxxxxx>; Shameer Kolothum
> Thodi <skolothumtho@xxxxxxxxxx>; alejandro.lucero-palau@xxxxxxx;
> dave@xxxxxxxxxxxx; jonathan.cameron@xxxxxxxxxx;
> alison.schofield@xxxxxxxxx; vishal.l.verma@xxxxxxxxx; ira.weiny@xxxxxxxxx;
> dan.j.williams@xxxxxxxxx; jgg@xxxxxxxx; Yishai Hadas <yishaih@xxxxxxxxxx>;
> kevin.tian@xxxxxxxxx
> Cc: Neo Jia <cjia@xxxxxxxxxx>; Tarun Gupta (SW-GPU) <targupta@xxxxxxxxxx>;
> Zhi Wang <zhiw@xxxxxxxxxx>; Krishnakant Jaju <kjaju@xxxxxxxxxx>; linux-
> kernel@xxxxxxxxxxxxxxx; linux-cxl@xxxxxxxxxxxxxxx; kvm@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH 20/20] selftests/vfio: Fix VLA initialisation in
> vfio_pci_irq_set()
>
> External email: Use caution opening links or attachments
>
>
> 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.
Yes, sent this for review to David Matlack and linux-kselftest
>
> 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);