public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] line6: add midibuf init failure handling in line6_init_midi()
@ 2024-05-16 17:47 yskelg
  2024-05-16 18:58 ` Bjorn Helgaas
  2024-05-17  8:32 ` Takashi Iwai
  0 siblings, 2 replies; 8+ messages in thread
From: yskelg @ 2024-05-16 17:47 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai
  Cc: skhan, linux-kernel-mentees, Austin Kim, shjy180909, linux-sound,
	linux-kernel, Yunseong Kim

From: Yunseong Kim <yskelg@gmail.com>

This patch fixes potential memory allocation failures in the
line6_midibuf_init(). If either midibuf_in, midibuf_out allocation
line6_midibuf_init call failed, the allocated memory for line6midi
might have been leaked.

This patch introduces an error handling label and uses goto to jump there
in case of allocation failures. A kfree call is added to release any
partially allocated memory before returning the error code.

Signed-off-by: Yunseong Kim <yskelg@gmail.com>
---
 sound/usb/line6/midi.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c
index 0838632c788e..abcf58f46673 100644
--- a/sound/usb/line6/midi.c
+++ b/sound/usb/line6/midi.c
@@ -283,13 +283,18 @@ int line6_init_midi(struct usb_line6 *line6)
 
 	err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0);
 	if (err < 0)
-		return err;
+		goto error;
 
 	err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
 	if (err < 0)
-		return err;
+		goto error;
 
 	line6->line6midi = line6midi;
 	return 0;
+
+error:
+	kfree(line6midi);
+	return err;
+
 }
 EXPORT_SYMBOL_GPL(line6_init_midi);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-05-18  6:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-16 17:47 [PATCH] line6: add midibuf init failure handling in line6_init_midi() yskelg
2024-05-16 18:58 ` Bjorn Helgaas
2024-05-17  8:32 ` Takashi Iwai
2024-05-17 17:10   ` Yunseong Kim
2024-05-17 17:51     ` Takashi Iwai
2024-05-18  6:00       ` Yunseong Kim
2024-05-17 17:44   ` Bjorn Helgaas
2024-05-18  5:58     ` Yunseong Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox