Re: read /dev/iio:device0 return -1 (Invalid argument)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 4, 2016 at 1:34 PM, Jonathan Cameron <jic23@xxxxxxxxxx> wrote:
> On 04/01/16 04:59, Julio Cruz wrote:
>> Hi Jonathan,
>>
>> Previously, you help me about an issue related with data loss. You suggest
>> me to debug deep in the core elements. I will try to summarize the results
>> below for future reference.
>>
>> When there is not data available in the buffer (kfifo), and the application
>> try to read data (using "read" function), it return zero (0).
>>
>> If libiio will be used to read the data, there is a problem (detailed at
>> https://github.com/analogdevicesinc/libiio/issues/23). In brief, Paul
>> (pcercuei) suggest me that this issue must be manage by the driver, in this
>> case, return -EAGAIN when there is not data available [Resource temporarily
>> unavailable (POSIX.1)].
>>
>> After review the core elements as suggested, I changed the line (in
>> function iio_read_first_n_kfifo of kfifo_buf.c) as below:
>>
>> - return copied;
>> + return copied == 0 ? -EAGAIN: copied;
>>
>> Do you think will be OK like this?

I assume you are doing a blocking read. Because otherwise your situation
should already be  handled in industrialio-buffer.c: 143,

In iio_buffer_read_first_n_outer function we have:

»       »       ret = rb->access->read_first_n(rb, n, buf);
»       »       if (ret == 0 && (filp->f_flags & O_NONBLOCK))
»       »       »       ret = -EAGAIN;
»        } while (ret == 0);

Now, if you are doing a blocking read and your read() returns 0 then
there is a bug in IIO core and it must be fixed! :)

We should again investigate iio_buffer_read_first_n function where,
with a special attention to this condition:

Can you paste here the parameters/ret values for relevant
open and read system calls done by your application?

»       »       ret = wait_event_interruptible(rb->pollq,
»       »             iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size));
»       »       if (ret)
»       »       »       return ret;

This part should block until there is some data available.

> Hmm.. This is an interesting one (thanks for tracking it down)
>
> The man page for read indeed allows for this to occur.
>
>        When attempting to read a file (other than a pipe or  FIFO)  that  sup‐
>        ports non-blocking reads and has no data currently available:
>
>         *  If  O_NONBLOCK  is  set,  read()  shall  return −1 and set errno to
>            [EAGAIN].
>
>
> However the issue here is that this is an ABI change and there may
> unfortunately be code out there relying on it returning 0.
>
> Most of the time a read will only be made in response to poll informing the
> userspace code that there is something available.  Whilst obviously we
> should try and fix the case of it reading when there isn't, I am a little
> curious to how you hit this case.
>
> So what do others think?  Much chance of us breaking any userspace
> code by making this change?
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux