[PATCH 02/10] ALSA: hda: ext: Clean up streams if their initialization fails
Cezary Rojewski <[email protected]>
| Newsgroups | gmane.linux.sound |
|---|---|
| Message-ID | <[email protected]> |
snd_hdac_ext_stream_init_all() does not rollback changes done when the allocation fails. Fix that to simplify its usage. Signed-off-by: Cezary Rojewski <[email protected]> --- sound/hda/core/ext/stream.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sound/hda/core/ext/stream.c b/sound/hda/core/ext/stream.c index 4c7506d49f55..7237fd9bb4b6 100644 --- a/sound/hda/core/ext/stream.c +++ b/sound/hda/core/ext/stream.c @@ -94,6 +94,7 @@ int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx, int (*setup_op)(struct hdac_stream *, bool); int stream_tag = 0; int i, tag, idx = start_idx; + struct hdac_stream *s, *_s; if (pci->device == PCI_DEVICE_ID_INTEL_HDA_APL) setup_op = snd_hdac_apl_host_stream_setup; @@ -103,7 +104,7 @@ int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx, for (i = 0; i < num_stream; i++) { struct hdac_ext_stream *hext_stream = kzalloc_obj(*hext_stream); if (!hext_stream) - return -ENOMEM; + goto err_nomem; tag = ++stream_tag; snd_hdac_ext_stream_init(bus, hext_stream, idx, dir, tag); idx++; @@ -112,6 +113,14 @@ int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx, return 0; +err_nomem: + list_for_each_entry_safe(s, _s, &bus->stream_list, list) { + struct hdac_ext_stream *hext_stream = stream_to_hdac_ext_stream(s); + + list_del(&s->list); + kfree(hext_stream); + } + return -ENOMEM; } EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_init_all); -- 2.34.1