summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2014-10-16 13:33:26 +0200
committerFelipe Balbi <balbi@ti.com>2014-11-05 13:36:05 -0600
commitd23b4c3ee2d5cbdeaec9f8e7d8a9bdcc73836fb9 (patch)
treee12ed1da81a3977cd865ab428baad52075a83089 /drivers/usb/gadget
parent6e58ed578e2c65442b7a02deecc96e482c701654 (diff)
downloadlwn-d23b4c3ee2d5cbdeaec9f8e7d8a9bdcc73836fb9.tar.gz
lwn-d23b4c3ee2d5cbdeaec9f8e7d8a9bdcc73836fb9.zip
usb: gadget: f_midi: check kstrdup() return value
kstrdup() might fail, so check its return value and react appropriately. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/function/f_midi.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index bf329578c957..a920eee9e878 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -654,6 +654,14 @@ static struct snd_rawmidi_ops gmidi_out_ops = {
.trigger = f_midi_out_trigger
};
+static inline void f_midi_unregister_card(struct f_midi *midi)
+{
+ if (midi->card) {
+ snd_card_free(midi->card);
+ midi->card = NULL;
+ }
+}
+
/* register as a sound "card" */
static int f_midi_register_card(struct f_midi *midi)
{
@@ -715,10 +723,7 @@ static int f_midi_register_card(struct f_midi *midi)
return 0;
fail:
- if (midi->card) {
- snd_card_free(midi->card);
- midi->card = NULL;
- }
+ f_midi_unregister_card(midi);
return err;
}
@@ -967,15 +972,23 @@ int __init f_midi_bind_config(struct usb_configuration *c,
midi->func.disable = f_midi_disable;
midi->id = kstrdup(id, GFP_KERNEL);
+ if (id && !midi->id) {
+ status = -ENOMEM;
+ goto kstrdup_fail;
+ }
midi->buflen = buflen;
midi->qlen = qlen;
status = usb_add_function(c, &midi->func);
if (status)
- goto setup_fail;
+ goto add_fail;
return 0;
+add_fail:
+ kfree(midi->id);
+kstrdup_fail:
+ f_midi_unregister_card(midi);
setup_fail:
for (--i; i >= 0; i--)
kfree(midi->in_port[i]);