linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Josselin Costanzi <josselin.costanzi@mobile-devices.fr>
Cc: linux-iio <linux-iio@vger.kernel.org>
Subject: Re: [PATCH] iio: make blocking read wait for data
Date: Fri, 06 Jun 2014 17:40:07 +0200	[thread overview]
Message-ID: <5391E0D7.8050309@metafoo.de> (raw)
In-Reply-To: <CAJA4uhc+RdEmOgyK8f3VHTqgCdAbVtdko1EW8z3BDvFq8Y4Rzw@mail.gmail.com>

On 06/06/2014 05:12 PM, Josselin Costanzi wrote:
> 2014-06-06 16:38 GMT+02:00 Lars-Peter Clausen <lars@metafoo.de>:
>>
>> On 06/06/2014 04:30 PM, Josselin Costanzi wrote:
>>>
>>> Currently the IIO buffer blocking read only wait until at least one
>>> data element is available.
>>
>> But that is how it is supposed to work. With this patch for example you won't be able to read the last data from the buffer after the buffer has been disabled.
>
> I don't understand the usecase this patch breaks... If the buffer is
> disabled then we return what was read alreay.
>

If there is less data in the buffer than the amount of requested data you'll 
keep looping forever.

>
>> Or if for example n is not aligned to the sample size you'll also continue to loop forever.
>
> If n isn't aligned to the sample size, wouldn't iio_read_first_n_kfifo
> still return data multiple of samples size? In that case we would copy
> complete elements until we try to do a short read which would fail at
> n < kfifo_esize(&kf->kf) (in iio_read_first_n_kfifo).
>

The read_first_n() callback will make sure that it only returns full 
samples, which means if n is smaller than the sample size it will return 0.

Now in your patch you have
	do {
		ret = read_first_n(..., n, ...);
		n -= ret;
	} while (n > 0);

So if n is not a multiple of the sample size you'll end up with n being 
smaller than the size of one sample but larger than 0 and at that point 
read_first_n() will always return 0 and n will stay at its current value. 
This means the exit condition of the while loop will never be met and you 
keep on looping forever.

Maybe start with which problem you are trying to address with this patch and 
then we can work forward from there to a solution. The current form of the 
patch changes the semantics of read() in a way they shouldn't be changed, so 
this is not only about the implementation bugs.

- Lars

  reply	other threads:[~2014-06-06 15:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-06 14:30 [PATCH] iio: make blocking read wait for data Josselin Costanzi
2014-06-06 14:38 ` Lars-Peter Clausen
2014-06-06 15:12   ` Josselin Costanzi
2014-06-06 15:40     ` Lars-Peter Clausen [this message]
2014-06-06 17:15       ` Josselin Costanzi
2014-06-07 10:18         ` Jonathan Cameron
2014-06-09 19:57           ` Lars-Peter Clausen
2014-06-09 20:12             ` Jonathan Cameron
2014-06-10 10:55               ` Josselin Costanzi
2014-06-10 15:23                 ` Srinivas Pandruvada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5391E0D7.8050309@metafoo.de \
    --to=lars@metafoo.de \
    --cc=josselin.costanzi@mobile-devices.fr \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).