Skip to content

Commit e7694cb

Browse files
Zhang Qilonggregkh
authored andcommitted
usb: gadget: f_midi: Fix memleak in f_midi_alloc
In the error path, if midi is not null, we should free the midi->id if necessary to prevent memleak. Fixes: b85e9de ("usb: gadget: f_midi: convert to new function interface with backward compatibility") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> Link: https://lore.kernel.org/r/20201117021629.1470544-2-zhangqilong3@huawei.com Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9ca5751 commit e7694cb

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/usb/gadget/function/f_midi.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
13151315
midi->id = kstrdup(opts->id, GFP_KERNEL);
13161316
if (opts->id && !midi->id) {
13171317
status = -ENOMEM;
1318-
goto setup_fail;
1318+
goto midi_free;
13191319
}
13201320
midi->in_ports = opts->in_ports;
13211321
midi->out_ports = opts->out_ports;
@@ -1327,7 +1327,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
13271327

13281328
status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL);
13291329
if (status)
1330-
goto setup_fail;
1330+
goto midi_free;
13311331

13321332
spin_lock_init(&midi->transmit_lock);
13331333

@@ -1343,9 +1343,13 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
13431343

13441344
return &midi->func;
13451345

1346+
midi_free:
1347+
if (midi)
1348+
kfree(midi->id);
1349+
kfree(midi);
13461350
setup_fail:
13471351
mutex_unlock(&opts->lock);
1348-
kfree(midi);
1352+
13491353
return ERR_PTR(status);
13501354
}
13511355

0 commit comments

Comments
 (0)