[PATCH 01/10] ALSA: hda: ext: Clean up links if their initialization fails
Cezary Rojewski <[email protected]>
| Newsgroups | gmane.linux.sound |
|---|---|
| Message-ID | <[email protected]> |
snd_hdac_ext_bus_get_ml_capabilities() allocates the hlink nodes one-by-one but the procedure may fails due to -ENOMEM in the middle of it. Clean up the list before returning the error code to simply the function usage. Signed-off-by: Cezary Rojewski <[email protected]> --- sound/hda/core/ext/controller.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sound/hda/core/ext/controller.c b/sound/hda/core/ext/controller.c index b1f1eff1d181..f75d3dcc6cb2 100644 --- a/sound/hda/core/ext/controller.c +++ b/sound/hda/core/ext/controller.c @@ -81,7 +81,7 @@ int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus) { int idx; u32 link_count; - struct hdac_ext_link *hlink; + struct hdac_ext_link *hlink, *save; u32 leptr; link_count = readl(bus->mlcap + AZX_REG_ML_MLCD) + 1; @@ -91,7 +91,7 @@ int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus) for (idx = 0; idx < link_count; idx++) { hlink = kzalloc_obj(*hlink); if (!hlink) - return -ENOMEM; + goto err_nomem; hlink->index = idx; hlink->bus = bus; hlink->ml_addr = bus->mlcap + AZX_ML_BASE + @@ -112,6 +112,13 @@ int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus) } return 0; + +err_nomem: + list_for_each_entry_safe(hlink, save, &bus->hlink_list, list) { + list_del(&hlink->list); + kfree(hlink); + } + return -ENOMEM; } EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_get_ml_capabilities); -- 2.34.1