Skip to content
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

i2s_driver_cleanup in i2s_stream_idf5.c->i2s_stream_init() is not safe (AUD-5308) #1182

Open
3 tasks done
yyjdelete opened this issue Mar 28, 2024 · 2 comments
Open
3 tasks done
Labels
Type: Bug Something isn't working

Comments

@yyjdelete
Copy link

yyjdelete commented Mar 28, 2024

INSTRUCTIONS

Before submitting a new issue, please follow the checklist and try to find the answer.

  • I have read the documentation Espressif Audio Development Guide and the issue is not addressed there.
  • I have updated my ADF and IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

for some app like examples/speech_recognition/wwe, if you switch the order of setup_player() and start_recorder(), and create the 2nd i2s_stream while the first one is working.

The 2nd call to i2s_stream_init will delete the old handle and create an new one, but not mutex for this, and it doesn't check config->uninstall_drv, so another i2s_stream maybe still using it.

i2s_driver_cleanup(i2s, false);

ret |= i2s_del_channel(i2s_key_slot[i2s->port].rx_handle);
i2s_key_slot[i2s->port].rx_handle = NULL;

static int _i2s_read(audio_element_handle_t self, char *buffer, int len, TickType_t ticks_to_wait, void *context)
{
size_t bytes_read = 0;
i2s_stream_t *i2s = (i2s_stream_t *)audio_element_getdata(self);
i2s_channel_read(i2s_key_slot[i2s->port].rx_handle, buffer, len, &bytes_read, ticks_to_wait);
audio_element_update_total_bytes(self, bytes_read);
return bytes_read;
}

It may lead to random crash(i2s reader block forever on deleted mutex or random broken memory).
And require an safe way to do it as it does in the old i2s_stream.c

@github-actions github-actions bot changed the title i2s_driver_cleanup in i2s_stream_idf5.c->i2s_stream_init() is not safe i2s_driver_cleanup in i2s_stream_idf5.c->i2s_stream_init() is not safe (AUD-5308) Mar 28, 2024
@jason-mao
Copy link
Collaborator

@yyjdelete Thanks for your report, let's fix it.

@jason-mao jason-mao added the Type: Bug Something isn't working label Apr 7, 2024
@shootao
Copy link

shootao commented Jul 12, 2024

Hi @yyjdelete
Please update i2s_stream_idf5.zip and have a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants