Repository navigation
mux: remove the wrong error message #4174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,20 +209,18 @@ static void mux_free(struct comp_dev *dev) | |
| rfree(dev); | ||
| } | ||
|
|
||
| static uint8_t get_stream_index(struct comp_data *cd, uint32_t pipe_id) | ||
| static int get_stream_index(struct comp_data *cd, uint32_t pipe_id) | ||
| { | ||
| int i; | ||
| int idx; | ||
|
|
||
| for (i = 0; i < MUX_MAX_STREAMS; i++) { | ||
| comp_cl_err(&comp_mux, "got %u", cd->config.streams[i].pipeline_id); | ||
| if (cd->config.streams[i].pipeline_id == pipe_id) | ||
| return i; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keyonjie the change looks good. But I wonder if the return 0 at the of the function is correct? If a match is not found, we should return a negative value isn't it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's a good point. I think the intention of the original author just wanted to return and use the first index (0) if the matched one not found, please check in the caller side, they don't check the return value and just use it as index blindly.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually this is unsafe as it's used for an array lookup and may assign a source/sink for usage that is not in the correct state (and may crash etc). Can we check the result and return an error here (and handle it in the caller.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure, let me add a commit to address this. |
||
| for (idx = 0; idx < MUX_MAX_STREAMS; idx++) | ||
| if (cd->config.streams[idx].pipeline_id == pipe_id) | ||
| return idx; | ||
|
|
||
| comp_cl_err(&comp_mux, "get_stream_index(): couldn't find configuration for connected pipeline %u", | ||
| pipe_id); | ||
|
|
||
| return 0; | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| static struct mux_look_up *get_lookup_table(struct comp_data *cd, | ||
|
|
@@ -423,12 +421,12 @@ static int demux_copy(struct comp_dev *dev) | |
| struct mux_look_up *look_up; | ||
| struct list_item *clist; | ||
| uint32_t num_sinks = 0; | ||
| uint32_t i = 0; | ||
| uint32_t frames = -1; | ||
| uint32_t source_bytes; | ||
| uint32_t avail; | ||
| uint32_t sinks_bytes[MUX_MAX_STREAMS] = { 0 }; | ||
| uint32_t flags = 0; | ||
| int i; | ||
|
|
||
| comp_dbg(dev, "demux_copy()"); | ||
|
|
||
|
|
@@ -445,6 +443,9 @@ static int demux_copy(struct comp_dev *dev) | |
| if (sink->sink->state == dev->state) { | ||
| num_sinks++; | ||
| i = get_stream_index(cd, sink->pipeline_id); | ||
| /* return if index wrong */ | ||
| if (i < 0) | ||
| return i; | ||
| look_up = get_lookup_table(cd, sink->pipeline_id); | ||
| sinks[i] = sink; | ||
| look_ups[i] = look_up; | ||
|
|
@@ -521,11 +522,11 @@ static int mux_copy(struct comp_dev *dev) | |
| const struct audio_stream *sources_stream[MUX_MAX_STREAMS] = { NULL }; | ||
| struct list_item *clist; | ||
| uint32_t num_sources = 0; | ||
| uint32_t i = 0; | ||
| uint32_t frames = -1; | ||
| uint32_t sources_bytes[MUX_MAX_STREAMS] = { 0 }; | ||
| uint32_t sink_bytes; | ||
| uint32_t flags = 0; | ||
| int i; | ||
|
|
||
| comp_dbg(dev, "mux_copy()"); | ||
|
|
||
|
|
@@ -542,6 +543,9 @@ static int mux_copy(struct comp_dev *dev) | |
| if (source->source->state == dev->state) { | ||
| num_sources++; | ||
| i = get_stream_index(cd, source->pipeline_id); | ||
| /* return if index wrong */ | ||
| if (i < 0) | ||
| return i; | ||
| sources[i] = source; | ||
| sources_stream[i] = &source->stream; | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
idxinstead ofi.