sof icon indicating copy to clipboard operation
sof copied to clipboard

[BUG][IPC4] wrong error handling in IPC4, potentially leading to missed failures

Open lyakh opened this issue 3 years ago • 3 comments

Describe the bug Files under src/ipc/ipc4/ mostly use error codes from enum ipc4_status which includes 0 as IPC4_SUCCESS and positive integer values as errors, but some code in that directory also uses negative POSIX return codes to indicate errors. Sometimes those codes are mixed. Sometimes checks like if (ret < 0) are performed where IPC4 errors are returned, so errors will be missed. An attempt has been made before in #5276 to fix those issues but it failed.

Code examples src/ipc/ipc4/helper.c:

static int ipc4_create_pipeline(struct ipc *ipc, uint32_t pipeline_id, uint32_t priority,
				uint32_t memory_size)
{
	...
	if (ipc_pipe) {
		...
		return IPC4_INVALID_RESOURCE_ID; // returning an IPC4_* error
	}
}

int ipc4_add_comp_dev(struct comp_dev *dev)
{
	...
	if (!icd) {
		...
		return IPC4_OUT_OF_MEMORY; // returning an IPC4_* error
	}
}

int ipc4_create_chain_dma(struct ipc *ipc, struct ipc4_chain_dma *cdma)
{
	ret = ipc4_create_pipeline(ipc, pipeline_id, 0, cdma->data.r.fifo_size);
	if (ret < 0) { // *BUG*: ipc4_create_pipeline() returns IPC4_* errors
	...
	ret = ipc4_add_comp_dev(host);
	if (ret < 0)
		return IPC4_FAILURE;
	...
}

static int ipc_pipeline_module_free(uint32_t pipeline_id)
{
	...
	ret = ipc_comp_free(ipc, icd->id);
	if (ret)
		return ret; // *BUG*: ipc_comp_free() returns negative POSIX codes
	...
}

int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id)
{
	...
	if (!ipc_pipe)
		return -ENODEV;
	...
	ret = pipeline_free(ipc_pipe->pipeline);
	if (ret < 0) {
		...
		return IPC4_INVALID_RESOURCE_STATE; // *BUG* mixed error codes
	}
	...
}

lyakh avatar Apr 26 '22 12:04 lyakh

@RanderWang @marcinszkudlinski @tmleman any comment or PR ?

lgirdwood avatar Apr 27 '22 10:04 lgirdwood

I will check and give fix

RanderWang avatar Apr 29 '22 08:04 RanderWang

A further bad example of mixing up POSIX and IPC4 error codes is https://github.com/thesofproject/sof/blob/main/src/audio/base_fw.c It must be fixed.

lyakh avatar Sep 26 '24 07:09 lyakh

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

github-actions[bot] avatar Jun 19 '25 03:06 github-actions[bot]