[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAEAJfD1kUJODa+-STV6Q+=9qWH8v2=KZzAA4ppgfbQxstO+Mg@mail.gmail.com>
Date: Wed, 26 Aug 2020 01:15:12 -0300
From: Ezequiel Garcia <ezequiel@...guardiasur.com.ar>
To: Alexandre Courbot <gnurou@...il.com>
Cc: Mauro Carvalho Chehab <mchehab@...nel.org>,
Hans Verkuil <hverkuil-cisco@...all.nl>,
Nicolas Dufresne <nicolas.dufresne@...labora.com>,
linux-media <linux-media@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] media: v4l2-mem2mem: simplify poll logic a bit
Hi Alexandre,
On Tue, 25 Aug 2020 at 11:56, Alexandre Courbot <gnurou@...il.com> wrote:
>
> Factorize redundant checks into a single code block, remove the early
> return, and declare variables in their innermost block. Hopefully this
> makes this code a little bit easier to follow.
>
This _definitely_ makes the poll handling more readable.
Reviewed-by: Ezequiel Garcia <ezequiel@...labora.com>
See below a nitpick.
> Signed-off-by: Alexandre Courbot <gnurou@...il.com>
> ---
> drivers/media/v4l2-core/v4l2-mem2mem.c | 35 +++++++++++---------------
> 1 file changed, 15 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
> index 0d0192119af20..aeac9707123d0 100644
> --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
> +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
> @@ -841,7 +841,6 @@ static __poll_t v4l2_m2m_poll_for_data(struct file *file,
> struct poll_table_struct *wait)
> {
> struct vb2_queue *src_q, *dst_q;
> - struct vb2_buffer *src_vb = NULL, *dst_vb = NULL;
> __poll_t rc = 0;
> unsigned long flags;
>
> @@ -863,33 +862,29 @@ static __poll_t v4l2_m2m_poll_for_data(struct file *file,
> return EPOLLERR;
>
> spin_lock_irqsave(&src_q->done_lock, flags);
> - if (!list_empty(&src_q->done_list))
> - src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer,
> - done_entry);
> - if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE
> - || src_vb->state == VB2_BUF_STATE_ERROR))
> - rc |= EPOLLOUT | EPOLLWRNORM;
> + if (!list_empty(&src_q->done_list)) {
> + struct vb2_buffer *src_vb = list_first_entry(
> + &src_q->done_list, struct vb2_buffer, done_entry);
> + if (src_vb->state == VB2_BUF_STATE_DONE ||
> + src_vb->state == VB2_BUF_STATE_ERROR)
> + rc |= EPOLLOUT | EPOLLWRNORM;
> + }
> spin_unlock_irqrestore(&src_q->done_lock, flags);
>
> spin_lock_irqsave(&dst_q->done_lock, flags);
> - if (list_empty(&dst_q->done_list)) {
> + if (!list_empty(&dst_q->done_list)) {
> + struct vb2_buffer *dst_vb = list_first_entry(
> + &dst_q->done_list, struct vb2_buffer, done_entry);
> + if (dst_vb->state == VB2_BUF_STATE_DONE ||
> + dst_vb->state == VB2_BUF_STATE_ERROR)
> + rc |= EPOLLIN | EPOLLRDNORM;
> + } else if (dst_q->last_buffer_dequeued) {
> /*
> * If the last buffer was dequeued from the capture queue,
> * return immediately. DQBUF will return -EPIPE.
> */
The part about "returning immediately" doesn't make
much sense now. Could we rephrase this, keeping the -EPIPE
comment?
Thanks,
Ezequiel
> - if (dst_q->last_buffer_dequeued) {
> - spin_unlock_irqrestore(&dst_q->done_lock, flags);
> - rc |= EPOLLIN | EPOLLRDNORM;
> - return rc;
> - }
> - }
> -
> - if (!list_empty(&dst_q->done_list))
> - dst_vb = list_first_entry(&dst_q->done_list, struct vb2_buffer,
> - done_entry);
> - if (dst_vb && (dst_vb->state == VB2_BUF_STATE_DONE
> - || dst_vb->state == VB2_BUF_STATE_ERROR))
> rc |= EPOLLIN | EPOLLRDNORM;
> + }
> spin_unlock_irqrestore(&dst_q->done_lock, flags);
>
> return rc;
> --
> 2.28.0
>
Powered by blists - more mailing lists