Re: [PATCHv2 1/2] usb: gadget: f_midi: use flexible array member for gmidi_in_port elements

From: Dan Carpenter
Date: Wed Jan 13 2016 - 15:42:01 EST


On Wed, Jan 13, 2016 at 06:26:22PM +0000, Felipe Ferreri Tonello wrote:
> > @@ -1115,26 +1112,16 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
> > }
> >
> > /* allocate and initialize one new instance */
> > - midi = kzalloc(sizeof(*midi), GFP_KERNEL);
> > + midi = kzalloc(
> > + sizeof(*midi) + opts->in_ports * sizeof(*midi->in_ports_array),
> > + GFP_KERNEL);
>
> Is there a garantee that the compiler will always use in_ports_array at
> the end of the allocated block?
>

Yes. It's fine. Zero size arrays at the end of a struct are normal.

regards,
dan carpenter