Skip to content

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

Closed as not planned

Description

@lyakh

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
	}
	...
}

Activity

  1. added
    bugSomething isn't working as expected
    P2Critical bugs or normal features
    on Apr 26, 2022
  2. lgirdwood commented on Apr 27, 2022

    @lgirdwood
    Member
  3. RanderWang commented on Apr 29, 2022

    @RanderWang
    Collaborator

    I will check and give fix

  4. lyakh commented on Sep 26, 2024

    @lyakh
    CollaboratorAuthor

    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.

  5. reopened this on Sep 26, 2024
  6. github-actions commented on Jun 19, 2025

    @github-actions

    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.

  7. added
    staleIssue/PR marked as stale and will be closed after 14 days if there is no activity.
    on Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Critical bugs or normal featuresbugSomething isn't working as expectedstaleIssue/PR marked as stale and will be closed after 14 days if there is no activity.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions