mirror of
https://github.com/torvalds/linux.git
synced 2026-09-13 15:40:03 +02:00
ALSA: hda/core: add cleanup in snd_hdac_bus_alloc_stream_pages()
The current error handling in snd_hdac_bus_alloc_stream_pages() returns directly on failure without cleaning up already allocated resources. While callers are supposed to release those via snd_hdac_bus_free_stream_pages() at destructor, adding explicit cleanup makes the function more self-contained and safer against future misuse. Add proper error cleanup path using goto labels to free previously allocated BDL DMA buffers, position buffer, and ring buffer in reverse allocation order. Signed-off-by: Zhao Dongdong <zhaodongdong@kylinos.cn> Link: https://patch.msgid.link/tencent_8E5BBBD19D53B1EFCDB6E89F3B6246A70B06@qq.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
bd8f218761
commit
f16eaa38ea
|
|
@ -719,7 +719,7 @@ int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus)
|
|||
BDL_SIZE, &s->bdl);
|
||||
num_streams++;
|
||||
if (err < 0)
|
||||
return -ENOMEM;
|
||||
goto error_bdl;
|
||||
}
|
||||
|
||||
if (WARN_ON(!num_streams))
|
||||
|
|
@ -728,12 +728,24 @@ int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus)
|
|||
err = snd_dma_alloc_pages(dma_type, bus->dev,
|
||||
num_streams * 8, &bus->posbuf);
|
||||
if (err < 0)
|
||||
return -ENOMEM;
|
||||
goto error_bdl;
|
||||
list_for_each_entry(s, &bus->stream_list, list)
|
||||
s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8);
|
||||
|
||||
/* single page (at least 4096 bytes) must suffice for both ringbuffes */
|
||||
return snd_dma_alloc_pages(dma_type, bus->dev, PAGE_SIZE, &bus->rb);
|
||||
err = snd_dma_alloc_pages(dma_type, bus->dev, PAGE_SIZE, &bus->rb);
|
||||
if (err < 0)
|
||||
goto error_posbuf;
|
||||
return 0;
|
||||
|
||||
error_posbuf:
|
||||
snd_dma_free_pages(&bus->posbuf);
|
||||
error_bdl:
|
||||
list_for_each_entry(s, &bus->stream_list, list) {
|
||||
if (s->bdl.area)
|
||||
snd_dma_free_pages(&s->bdl);
|
||||
}
|
||||
return -ENOMEM;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_hdac_bus_alloc_stream_pages);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user