From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 2/3] iio:kfifo: Empty buffer on update
Date: Mon, 14 Oct 2013 23:07:23 +0100 [thread overview]
Message-ID: <525C6B1B.7000709@kernel.org> (raw)
In-Reply-To: <1381763350-8930-2-git-send-email-lars@metafoo.de>
On 10/14/13 16:09, Lars-Peter Clausen wrote:
> The kfifo's request_update callback will free the current buffer and allocate a
> new one if the size has changed. This will remove any samples that might still
> be left in the buffer. If the size has not changed the buffer content is
> left untouched though. This is a bit inconsistent and might cause an application
> to see data from a previous capture. This patch inserts a call to
> kfifo_reset_out() when the size did not change. This makes sure that any pending
> samples are removed from the buffer.
>
> Note, due to a different bug the buffer is currently always re-allocated, even
> if the size did not change. So this patch will not change the behavior. In the
> next patch the bug will be fixed and this patch makes sure that the current
> behavior is kept.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Just a little preference on ordering in this one...
> ---
> drivers/iio/kfifo_buf.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
> index b7f4617..a050b18 100644
> --- a/drivers/iio/kfifo_buf.c
> +++ b/drivers/iio/kfifo_buf.c
> @@ -33,15 +33,17 @@ static int iio_request_update_kfifo(struct iio_buffer *r)
> int ret = 0;
> struct iio_kfifo *buf = iio_to_kfifo(r);
>
> - if (!buf->update_needed)
> - goto error_ret;
> mutex_lock(&buf->user_lock);
> - kfifo_free(&buf->kf);
> - ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum,
Would you mind flipping the logic on this? Feels more logical to me
(slightly) to have
if (buf->update_needed) {
...
} else {
kfifo_reset_out(..)
}
> + if (!buf->update_needed) {
> + kfifo_reset_out(&buf->kf);
> + } else {
> + kfifo_free(&buf->kf);
> + ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum,
> buf->buffer.length);
> + }
> r->stufftoread = false;
> mutex_unlock(&buf->user_lock);
> -error_ret:
> +
> return ret;
> }
>
>
next prev parent reply other threads:[~2013-10-14 21:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-14 15:09 [PATCH 1/3] iio:kfifo: Protect against concurrent access from userspace Lars-Peter Clausen
2013-10-14 15:09 ` [PATCH 2/3] iio:kfifo: Empty buffer on update Lars-Peter Clausen
2013-10-14 22:07 ` Jonathan Cameron [this message]
2013-10-14 15:09 ` [PATCH 3/3] iio:kfifo: Set update_needed to false after allocating a new buffer Lars-Peter Clausen
2013-10-14 22:07 ` Jonathan Cameron
2013-10-14 22:04 ` [PATCH 1/3] iio:kfifo: Protect against concurrent access from userspace Jonathan Cameron
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=525C6B1B.7000709@kernel.org \
--to=jic23@kernel.org \
--cc=lars@metafoo.de \
--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).