From 8f96d4178f4e28f2b4418835879c76aa64cbff37 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Tue, 1 Dec 2026 16:29:45 +0000 Subject: [PATCH] audio: copier: release DAI endpoints when DAI creation fails copier_dai_create() can fail after one or more copier_dai_init() calls succeeded: a later endpoint init can fail, get_converter_func() can find no converter for the host-supplied formats, or the ALH multi-endpoint buffer allocation can fail. These paths returned straight away and copier_init() then only freed the copier private data. Since the copier is never created, copier_free() never runs, so the resources taken by dai_common_new() and dai_config() were leaked: the DAI reference from dai_get(), the DMA reference, the dai_spec_config copy and the DAI group membership. The dai_data itself is reclaimed by the module memory cleanup, which also leaves a dangling entry on the DAI group list. Unwind with copier_dai_free(), which releases exactly the cd->endpoint_num endpoints that were initialized. Found with the IPC4 fuzzer: a DAI copier INIT_INSTANCE with a format combination that has no converter leaked three allocations per testcase. Signed-off-by: Tomasz Leman --- src/audio/copier/copier_dai.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/audio/copier/copier_dai.c b/src/audio/copier/copier_dai.c index 508972b4773c..35e283eecfb4 100644 --- a/src/audio/copier/copier_dai.c +++ b/src/audio/copier/copier_dai.c @@ -385,7 +385,7 @@ __cold int copier_dai_create(struct comp_dev *dev, struct copier_data *cd, dai_count); if (ret) { comp_err(dev, "failed to create dai"); - return ret; + goto err_free_dais; } } @@ -395,14 +395,15 @@ __cold int copier_dai_create(struct comp_dev *dev, struct copier_data *cd, if (!cd->converter[IPC4_COPIER_GATEWAY_PIN]) { comp_err(dev, "failed to get converter type %d, dir %d", cd->gtw_type, dai.direction); - return -EINVAL; + ret = -EINVAL; + goto err_free_dais; } /* create multi_endpoint_buffer for ALH multi-gateway case */ if (dai_count > 1) { ret = create_multi_endpoint_buffer(dev, cd, copier); if (ret < 0) - return ret; + goto err_free_dais; } if (cd->direction == SOF_IPC_STREAM_PLAYBACK) { @@ -415,6 +416,15 @@ __cold int copier_dai_create(struct comp_dev *dev, struct copier_data *cd, } return 0; + +err_free_dais: + /* The copier is not created, so copier_free() will never run for it. + * Release the DAI, DMA and DAI group references taken by the endpoints + * that were already initialized, they are not covered by the module + * memory cleanup. + */ + copier_dai_free(mod); + return ret; } __cold void copier_dai_free(struct processing_module *mod)