no-OS icon indicating copy to clipboard operation
no-OS copied to clipboard

tinyiio crashed when libiio refill was called on an empty tinyiio buffer.

Open kister-jimenez opened this issue 3 months ago • 1 comments

My assumption with the READBUF or when a refill call from the host using libiio is if the circular buffer used to store samples with a trigger handler is empty or less than what was configured as buffer size in the host, it should just get an -EAGAIN. However, it crashed the tinyiio and looking at the code here, https://github.com/analogdevicesinc/no-OS/blob/05c0d208758c1d60fd7009a5356146f76276fa4f/iio/iiod.c#L832 the -EAGAIN propagated to the iio_app instead of passing it to the conn->res.

Catching the -EAGAIN and preventing it from propagating to the calling functions solved the issue of crashing. But, libiio now returns a timeout when refill was called when circular buffer in tinyiio was empty, which is fine since we can just call the refill function with a backoff timer from the application. Is there a way to safely refill when tinyiio buffer is empty?

To replicate:

  1. You need an iio driver with a trigger handler (without .submit/read_rev ops) that fills the circullar buffer with samples. Use a large delay for example 5000ms per trigger. Set the number of samples pushed to 2 per trigger.
  2. You can create a very simple pyadi-iio (or maybe use iio cli toos) to get the buffer contents every 1 second. Set the buffer size to 2.
  3. If the interrupt started ahead of your .rx() call in pyadi-iio, you will get data until the buffer is empty and it will crash after a few timeouts and READ INTEGER and READLINE errors.

kister-jimenez avatar Sep 19 '25 13:09 kister-jimenez

Do you think you can replicate this issue using the timer_trigger_example of iio_demo (projects/iio_demo/src/examples/iio_timer_trigger_example/iio_timer_trigger_example.c) and iio_rwdev (iio_rwdev -u serial:/dev/ttyACM0,57600,8n1n -b 4 -s 4 -t adc_demo_timer_trig adc_demo | hexdump -C)?

ralucabozdog avatar Sep 23 '25 16:09 ralucabozdog