Skip to content

component: add check if comp_ops are available - #1177

Merged
lgirdwood merged 2 commits into
thesofproject:masterfrom
tlauda:topic/comp_ops_null
Apr 1, 2019
Merged

lgirdwood merged 2 commits into
thesofproject:masterfrom
tlauda:topic/comp_ops_null

Conversation

@tlauda

@tlauda tlauda commented Mar 22, 2019

Copy link
Copy Markdown
Contributor

Adds check if comp_ops are available.
Without this change there is a possibility of
exception.

Signed-off-by: Tomasz Lauda tomasz.lauda@linux.intel.com

@ranj063

ranj063 commented Mar 22, 2019

Copy link
Copy Markdown
Collaborator

@tlauda we ran into something similar in the driver as well where we had to alter the return value from ops.

Basically, some of the ops are OK to return 0 if not set, say for ex: params but something like trigger should return an error isnt it? So we should identify mandatory and optional ops and fix the return value accordingly.

@tlauda

tlauda commented Mar 22, 2019 •

Copy link
Copy Markdown
Contributor Author

@ranj063 Hard to decide which one should be mandatory and which one shouldn't. It really depends on the internal component implementation and purpose.

@ranj063

ranj063 commented Mar 22, 2019

Copy link
Copy Markdown
Collaborator

@tlauda i dont know about the others but comp_cmd should not return a 0. it will be misleading to the driver. I think we should return an error in that case

@lgirdwood

lgirdwood commented Mar 22, 2019 •

Copy link
Copy Markdown
Member

@ranj063 the general intention is that a non implemented operation will always return 0. i.e. the component does not care hence it has not implemented the operation.

@ranj063

ranj063 commented Mar 22, 2019

Copy link
Copy Markdown
Collaborator

@lgirdwood OK where I was coming from was that if we add a kcontrol to a component, ideally the comp should implement a cmd callback to process kcontrol IO data.

Comment thread src/include/sof/audio/component.h Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

comp ops, as an application level extension point, might be the first one and most popular area of the development based on SOF. That is why there should be strong verification of the API requirements enforced I believe. The documentation above says that ops.free() is mandatory which seems right since it might be better to enforce empty handler rather than allow for memory leaks. The proposed change quietly allows to skip the implementation which is inconsistent with the documented requirements. This one (as well as other handlers marked as mandatory like params()) seems to be a good candidate for assert(not null). And I would opt for assert() that compiles in non-debug version to panic (it might be difficult to deliver extra debug configuration on some platforms and force the use) to make sure that no mandatory part is missed during the component development process.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mmaka1 Ack, if it's mandatory we shout and let the user know. If optional we perform the check.

@tlauda tlauda added the P1 Blocker bugs or important features label Mar 26, 2019
@tlauda
tlauda force-pushed the topic/comp_ops_null branch from fcb2582 to 3f4a2f5 Compare March 28, 2019 14:46
@tlauda

tlauda commented Mar 28, 2019

Copy link
Copy Markdown
Contributor Author

@mmaka1 @lgirdwood I've added simple assert macro, which will cause panic. Params, prepare, cmd and reset ops shouldn't be mandatory, so I've changed the documentation.

@tlauda
tlauda force-pushed the topic/comp_ops_null branch from 3f4a2f5 to 412d904 Compare March 28, 2019 16:46
@tlauda
tlauda requested a review from jajanusz as a code owner March 28, 2019 16:46
@tlauda
tlauda force-pushed the topic/comp_ops_null branch 2 times, most recently from f22a36b to f9c26af Compare March 29, 2019 10:40
@tlauda
tlauda requested a review from ranj063 as a code owner March 29, 2019 10:40
@lgirdwood

Copy link
Copy Markdown
Member

@zrombel can this be requeued on CI as it should be back up now after down time. Would like to merge today.

@ranj063

ranj063 commented Mar 29, 2019

Copy link
Copy Markdown
Collaborator

@tlauda @lgirdwood i have an issue with comp_cmd() returning 0 if not implemented.
It is not a mandatory op but when the driver issues a get() command it is expecting data back from the comp and does it make sense to return a 0 even if we dont really handle the request?

@lgirdwood

Copy link
Copy Markdown
Member

@ranj063 It looks like this would only be a problem if topology incorrectly added kcontrols for a component that does not have any, so your right we should have -EINVAL for this case. @tlauda small update needed.

tlauda added 2 commits March 30, 2019 10:33
Adds assert macro to easily locate wrong
parameters. If condition is not met we
will panic.

Signed-off-by: Tomasz Lauda <tomasz.lauda@linux.intel.com>
Adds check if optional comp_ops are available.
This patch also adds assert for mandatory ops.

Signed-off-by: Tomasz Lauda <tomasz.lauda@linux.intel.com>
@tlauda
tlauda force-pushed the topic/comp_ops_null branch from f9c26af to 29af0cc Compare March 30, 2019 09:37
@tlauda

tlauda commented Mar 30, 2019

Copy link
Copy Markdown
Contributor Author

@lgirdwood @ranj063 Updated.

@ranj063 ranj063 left a comment

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.

looks good. Thanks @tlauda

@tlauda

tlauda commented Apr 1, 2019

Copy link
Copy Markdown
Contributor Author

@lgirdwood The only question remains if the ABI change is needed. Kernel change: thesofproject/linux#762.

@lgirdwood
lgirdwood merged commit c145543 into thesofproject:master Apr 1, 2019
@tlauda
tlauda deleted the topic/comp_ops_null branch November 22, 2019 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Blocker bugs or important features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants