Skip to content

ASoC: SOF: ipc4-compress: Add NULL checks for pcm_ops - #5905

Open
naveen-manohar wants to merge 1 commit into
thesofproject:topic/sof-devfrom
naveen-manohar:ww361_sof-dev_push_deref_push
Open

ASoC: SOF: ipc4-compress: Add NULL checks for pcm_ops#5905
naveen-manohar wants to merge 1 commit into
thesofproject:topic/sof-devfrom
naveen-manohar:ww361_sof-dev_push_deref_push

Conversation

@naveen-manohar

Copy link
Copy Markdown

Patch adds NULL checks before dereferencing pcm_ops
to prevent potential NULL pointer deref issues & fix
-Werror=analyzer-null-dereference build failures.

Addresses Issue - https://github.com/thesofproject/linux/actions/runs/33356184832/job/99378699428?pr=5903

Patch adds NULL checks before dereferencing pcm_ops to
prevent potential NULL pointer deref issues & fix
-Werror=analyzer-null-dereference build failures.

Signed-off-by: Naveen Manohar <naveen.m@intel.com>
int err = 0;

if (!pcm_ops)
return -EINVAL;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ujfalusi Is it possible be NULL?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During normal stream ops sdev->ipc->ops is always set, so pcm_ops will not be NULL at runtime.
But sof_ipc_get_ops(sdev, pcm) evaluates to
((sdev)->ipc && (sdev)->ipc->ops) ? (sdev)->ipc->ops->pcm : NULL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes? This is granted to be never NULL.

int err = 0;

if (!pcm_ops)
return -EINVAL;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is granted to be not NULL.

int ret = 0;

if (!pcm_ops || !pcm_ops->trigger)
return -EINVAL;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this is granted.
This is IPC4 compress code, supporting IPC4, IPC4 have these callbacks, ops.
If we are in DSPless mode than the pd->compress_ops is kept NULL, so this code cannot be called.

The report is bogus.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only reason for this PR is,
SOF CI job build test / GCC static -fanalyzer FAILS with -Werror=analyzer-null-dereference because of NULL branch in sof_ipc_get_ops()
Leading to https://github.com/thesofproject/linux/actions/runs/33356184832/job/99378699428?pr=5903

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, static analyzer is wrong.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even other soc-vendors also observes similar issue - but atleast with this PR, Intel is fine
https://github.com/thesofproject/linux/actions/runs/33360526770/job/99390844949?pr=5905

Else do you recommend to handle this at macro level(something like correcting sof_ipc_get_ops() in sof-priv.h), instead of scattering NULL checks in individual audio stream.
Or do you recommend to Leave this as is ?
Please share your thoughts. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants