Skip to content

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

Open
@yyjdelete

Description

@yyjdelete

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions