From d4659aaf2d3c58f5f9fc332b15942efc60954356 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 18 Aug 2026 11:35:08 +0200 Subject: [PATCH 1/2] ipc: ipc4: remove a memcpy() in MOD_INIT_INSTANCE Use a type-cast instead of a memcpy() to obtain struct ipc4_module_init_instance data. Signed-off-by: Guennadi Liakhovetski --- src/ipc/ipc4/handler-user.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/ipc/ipc4/handler-user.c b/src/ipc/ipc4/handler-user.c index 5888b007ed42..b5fbda6a2f9a 100644 --- a/src/ipc/ipc4/handler-user.c +++ b/src/ipc/ipc4/handler-user.c @@ -1513,28 +1513,25 @@ __cold int ipc4_user_process_module_message(struct ipc4_message_request *ipc4, case SOF_IPC4_MOD_INIT_INSTANCE: #ifdef CONFIG_SOF_USERSPACE_LL { + BUILD_ASSERT(sizeof(struct comp_driver) + sizeof(struct tr_ctx) <= + sizeof(((struct ipc_user *)0)->init_drv_data), + "ipc_user.init_drv_data too small for driver copy"); + /* User-space init: kernel does driver lookup only (requires * access to IMR manifest and driver list in kernel memory). * Component creation (drv->ops.create) runs in user thread * so untrusted module code does not execute in kernel context. * Cross-core creation stays fully in kernel. */ - struct ipc4_module_init_instance mi; - - BUILD_ASSERT(sizeof(struct comp_driver) + sizeof(struct tr_ctx) <= - sizeof(((struct ipc_user *)0)->init_drv_data), - "ipc_user.init_drv_data too small for driver copy"); - - ret = memcpy_s(&mi, sizeof(mi), ipc4, sizeof(*ipc4)); - if (ret < 0) - break; + const struct ipc4_module_init_instance *mi = + (const struct ipc4_module_init_instance *)ipc4; - if (!cpu_is_me(mi.extension.r.core_id)) { + if (!cpu_is_me(mi->extension.r.core_id)) { ret = ipc4_init_module_instance(ipc4); } else { struct ipc *ipc = ipc_get(); - uint32_t comp_id = IPC4_COMP_ID(mi.primary.r.module_id, - mi.primary.r.instance_id); + uint32_t comp_id = IPC4_COMP_ID(mi->primary.r.module_id, + mi->primary.r.instance_id); const struct comp_driver *drv = ipc4_get_comp_drv( IPC4_MOD_ID(comp_id)); struct ipc_user *pdata = ipc->ipc_user_pdata; From 992c1e22ca39e0a06efdd6581904c28dc46fbd67 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 3 Aug 2026 09:26:48 +0200 Subject: [PATCH 2/2] ipc: (cosmetic) compact several lines Join several needlessly broken lines. Signed-off-by: Guennadi Liakhovetski --- src/ipc/ipc-helper.c | 21 +++++++-------------- src/ipc/ipc4/helper.c | 43 ++++++++++++++----------------------------- 2 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index 567255a9e22a..4c46d104856f 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -82,8 +82,7 @@ __cold struct comp_buffer *buffer_new(struct mod_alloc_ctx *alloc, #endif /* allocate buffer */ - buffer = buffer_alloc(alloc, desc->size, flags, PLATFORM_DCACHE_ALIGN, - is_shared); + buffer = buffer_alloc(alloc, desc->size, flags, PLATFORM_DCACHE_ALIGN, is_shared); if (buffer) { buffer->stream.runtime_stream_params.id = desc->comp.id; buffer->stream.runtime_stream_params.pipeline_id = desc->comp.pipeline_id; @@ -188,14 +187,12 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag, if (dir == PPL_DIR_DOWNSTREAM) { comp_dev_for_each_consumer(dev, buf) { comp_update_params(flag, params, buf); - buffer_set_params(buf, params, - BUFFER_UPDATE_FORCE); + buffer_set_params(buf, params, BUFFER_UPDATE_FORCE); } } else { comp_dev_for_each_producer(dev, buf) { comp_update_params(flag, params, buf); - buffer_set_params(buf, params, - BUFFER_UPDATE_FORCE); + buffer_set_params(buf, params, BUFFER_UPDATE_FORCE); } } @@ -284,11 +281,9 @@ int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id) pipeline_id = ipc_pipe->pipeline->pipeline_id; - tr_dbg(&ipc_tr, "ipc: pipe %d -> complete on comp 0x%x", pipeline_id, - comp_id); + tr_dbg(&ipc_tr, "ipc: pipe %d -> complete on comp 0x%x", pipeline_id, comp_id); - return pipeline_complete(ipc_pipe->pipeline, ipc_ppl_source->cd, - ipc_ppl_sink->cd); + return pipeline_complete(ipc_pipe->pipeline, ipc_ppl_source->cd, ipc_ppl_sink->cd); } __cold int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) @@ -306,8 +301,7 @@ __cold int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) /* check whether component exists */ icd = ipc_get_comp_by_id(ipc, comp_id); if (!icd) { - tr_err(&ipc_tr, "comp id: 0x%x is not found", - comp_id); + tr_err(&ipc_tr, "comp id: 0x%x is not found", comp_id); return -ENODEV; } @@ -336,8 +330,7 @@ __cold int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) * leak on error. Bug-free host drivers won't do * this, this was found via fuzzing. */ - tr_err(&ipc_tr, "uninitialized buffer lists on comp 0x%x\n", - icd->id); + tr_err(&ipc_tr, "uninitialized buffer lists on comp 0x%x\n", icd->id); return -EINVAL; } diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index f1e112fb37ea..a714afc6e817 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -295,9 +295,7 @@ __cold struct comp_dev *comp_new_ipc4_user(struct ipc4_message_request *ipc4, ipc_config.proc_domain = COMP_PROCESSING_DOMAIN_LL; #else if (module_init.extension.r.proc_domain) { - tr_err(&ipc_tr, - "ipc: DP scheduling is disabled, cannot create comp 0x%x", - comp_id); + tr_err(&ipc_tr, "ipc: DP scheduling is disabled, cannot create comp 0x%x", comp_id); return NULL; } ipc_config.proc_domain = COMP_PROCESSING_DOMAIN_LL; @@ -1166,8 +1164,7 @@ __cold int ipc4_chain_manager_create(const struct ipc4_chain_dma *cdma) const uint32_t comp_id = IPC4_COMP_ID(cdma->primary.r.host_dma_id + IPC4_MAX_MODULE_COUNT, 0); dev->ipc_config.id = comp_id; - dev->ipc_config.pipeline_id = cdma->primary.r.host_dma_id - + IPC4_MAX_MODULE_COUNT; + dev->ipc_config.pipeline_id = cdma->primary.r.host_dma_id + IPC4_MAX_MODULE_COUNT; return ipc4_add_comp_dev(dev); } @@ -1309,13 +1306,10 @@ __cold static const struct comp_driver *ipc4_search_for_drv(const void *uuid) /* search driver list with UUID */ list_for_item(clist, &drivers->list) { - info = container_of(clist, struct comp_driver_info, - list); + info = container_of(clist, struct comp_driver_info, list); if (!memcmp(info->drv->uid, uuid, UUID_SIZE)) { - tr_dbg(&comp_tr, - "found type %d, uuid %pU", - info->drv->type, - info->drv->tctx->uuid_p); + tr_dbg(&comp_tr, "found type %d, uuid %pU", + info->drv->type, info->drv->tctx->uuid_p); drv = info->drv; break; } @@ -1397,8 +1391,7 @@ static const struct comp_driver *ipc4_get_fuzzer_drv(uint32_t module_id) return inf->drv; } - tr_err(&comp_tr, - "no instantiable driver at module_id %u (%u available)", + tr_err(&comp_tr, "no instantiable driver at module_id %u (%u available)", module_id, idx); return NULL; } @@ -1642,10 +1635,8 @@ void ipc4_audio_format_to_stream_params(const struct ipc4_audio_format *audio_fm params->sample_valid_bytes = audio_fmt->valid_bit_depth / 8; params->buffer_fmt = audio_fmt->interleaving_style; - audio_stream_fmt_conversion(audio_fmt->depth, - audio_fmt->valid_bit_depth, - &frame_fmt, &valid_fmt, - audio_fmt->s_type); + audio_stream_fmt_conversion(audio_fmt->depth, audio_fmt->valid_bit_depth, + &frame_fmt, &valid_fmt, audio_fmt->s_type); params->frame_fmt = frame_fmt; for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++) @@ -1670,10 +1661,8 @@ void ipc4_update_buffer_format(struct comp_buffer *buf_c, audio_stream_set_channels(&buf_c->stream, fmt->channels_count); audio_stream_set_rate(&buf_c->stream, fmt->sampling_frequency); - audio_stream_fmt_conversion(fmt->depth, - fmt->valid_bit_depth, - &frame_fmt, &valid_fmt, - fmt->s_type); + audio_stream_fmt_conversion(fmt->depth, fmt->valid_bit_depth, + &frame_fmt, &valid_fmt, fmt->s_type); audio_stream_set_frm_fmt(&buf_c->stream, frame_fmt); audio_stream_set_valid_fmt(&buf_c->stream, valid_fmt); @@ -1692,10 +1681,8 @@ void ipc4_update_source_format(struct sof_source *source, source_set_channels(source, fmt->channels_count); source_set_rate(source, fmt->sampling_frequency); - audio_stream_fmt_conversion(fmt->depth, - fmt->valid_bit_depth, - &frame_fmt, &valid_fmt, - fmt->s_type); + audio_stream_fmt_conversion(fmt->depth, fmt->valid_bit_depth, + &frame_fmt, &valid_fmt, fmt->s_type); source_set_frm_fmt(source, frame_fmt); source_set_valid_fmt(source, valid_fmt); @@ -1710,10 +1697,8 @@ void ipc4_update_sink_format(struct sof_sink *sink, sink_set_channels(sink, fmt->channels_count); sink_set_rate(sink, fmt->sampling_frequency); - audio_stream_fmt_conversion(fmt->depth, - fmt->valid_bit_depth, - &frame_fmt, &valid_fmt, - fmt->s_type); + audio_stream_fmt_conversion(fmt->depth, fmt->valid_bit_depth, + &frame_fmt, &valid_fmt, fmt->s_type); sink_set_frm_fmt(sink, frame_fmt); sink_set_valid_fmt(sink, valid_fmt);