Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1311645 > unrolled thread
| Started by | Michal Nazarewicz <mina86@mina86.com> |
|---|---|
| First post | 2016-01-18 17:10 +0100 |
| Last post | 2016-01-19 10:50 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCHv2 1/2] usb: gadget: f_midi: use flexible array member for gmidi_in_port elements Michal Nazarewicz <mina86@mina86.com> - 2016-01-18 17:10 +0100
Re: [PATCHv2 1/2] usb: gadget: f_midi: use flexible array member for gmidi_in_port elements Felipe Ferreri Tonello <eu@felipetonello.com> - 2016-01-19 10:50 +0100
| From | Michal Nazarewicz <mina86@mina86.com> |
|---|---|
| Date | 2016-01-18 17:10 +0100 |
| Subject | Re: [PATCHv2 1/2] usb: gadget: f_midi: use flexible array member for gmidi_in_port elements |
| Message-ID | <qSkxr-2ZZ-13@gated-at.bofh.it> |
> On 09/01/16 03:47, Michal Nazarewicz wrote:
>> @@ -55,7 +55,6 @@ static const char f_midi_longname[] = "MIDI Gadget";
>> * USB <- IN endpoint <- rawmidi
>> */
>> struct gmidi_in_port {
>> - struct f_midi *midi;
On Wed, Jan 13 2016, Felipe Ferreri Tonello wrote:
> This change is unrelated. I sent a patch removing this pointer as well.
Has it been merged yet? Which branch? Could you point me to the patch?
>> int active;
>> uint8_t cable;
>> uint8_t state;
>> @@ -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?
Yep, see <https://en.wikipedia.org/wiki/Flexible_array_member>.
>
>> if (!midi) {
>> mutex_unlock(&opts->lock);
>> return ERR_PTR(-ENOMEM);
>> }
>>
>> - for (i = 0; i < opts->in_ports; i++) {
>> - struct gmidi_in_port *port = kzalloc(sizeof(*port), GFP_KERNEL);
>> -
>> - if (!port) {
>> - status = -ENOMEM;
>> - mutex_unlock(&opts->lock);
>> - goto setup_fail;
>> - }
>> -
>> - port->midi = midi;
>> - port->active = 0;
>> - port->cable = i;
>> - midi->in_port[i] = port;
>> - }
>> + for (i = 0; i < opts->in_ports; i++)
>> + midi->in_ports_array[i].cable = i;
>>
>> /* set up ALSA midi devices */
>> midi->id = kstrdup(opts->id, GFP_KERNEL);
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, ミハウ “mina86” ナザレヴイツ (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--
[toc] | [next] | [standalone]
| From | Felipe Ferreri Tonello <eu@felipetonello.com> |
|---|---|
| Date | 2016-01-19 10:50 +0100 |
| Subject | Re: [PATCHv2 1/2] usb: gadget: f_midi: use flexible array member for gmidi_in_port elements |
| Message-ID | <qSB5f-5UF-7@gated-at.bofh.it> |
| In reply to | #1311645 |
[Multipart message — attachments visible in raw view] — view raw
Hi Michal,
On 18/01/16 16:02, Michal Nazarewicz wrote:
>> On 09/01/16 03:47, Michal Nazarewicz wrote:
>>> @@ -55,7 +55,6 @@ static const char f_midi_longname[] = "MIDI Gadget";
>>> * USB <- IN endpoint <- rawmidi
>>> */
>>> struct gmidi_in_port {
>>> - struct f_midi *midi;
>
> On Wed, Jan 13 2016, Felipe Ferreri Tonello wrote:
>> This change is unrelated. I sent a patch removing this pointer as well.
>
> Has it been merged yet? Which branch? Could you point me to the patch?
No, but it is in the mailing list.
"[PATCH 3/4] usb: gadget: f_midi: remove useless midi reference from
port struct" under "[PATCH 0/4] More improvements on MIDI gadget function"
>
>>> int active;
>>> uint8_t cable;
>>> uint8_t state;
>>> @@ -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?
>
> Yep, see <https://en.wikipedia.org/wiki/Flexible_array_member>.
Thanks.
Felipe
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web