Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: v4l2-mem2mem: simplify poll logic

Factorize redundant checks into a single code block, remove unneeded
checks (a buffer in done_list is necessarily in the DONE or ERROR
state), and we end up with a much simpler version of this function.

Signed-off-by: Alexandre Courbot <gnurou@gmail.com>
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Alexandre Courbot and committed by
Mauro Carvalho Chehab
1698a7f1 566463af

+5 -21
+5 -21
drivers/media/v4l2-core/v4l2-mem2mem.c
··· 882 882 struct poll_table_struct *wait) 883 883 { 884 884 struct vb2_queue *src_q, *dst_q; 885 - struct vb2_buffer *src_vb = NULL, *dst_vb = NULL; 886 885 __poll_t rc = 0; 887 886 unsigned long flags; 888 887 ··· 902 903 list_empty(&dst_q->queued_list))) 903 904 return EPOLLERR; 904 905 905 - spin_lock_irqsave(&dst_q->done_lock, flags); 906 - if (list_empty(&dst_q->done_list)) { 907 - /* 908 - * If the last buffer was dequeued from the capture queue, 909 - * return immediately. DQBUF will return -EPIPE. 910 - */ 911 - if (dst_q->last_buffer_dequeued) 912 - rc |= EPOLLIN | EPOLLRDNORM; 913 - } 914 - spin_unlock_irqrestore(&dst_q->done_lock, flags); 915 - 916 906 spin_lock_irqsave(&src_q->done_lock, flags); 917 907 if (!list_empty(&src_q->done_list)) 918 - src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer, 919 - done_entry); 920 - if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE 921 - || src_vb->state == VB2_BUF_STATE_ERROR)) 922 908 rc |= EPOLLOUT | EPOLLWRNORM; 923 909 spin_unlock_irqrestore(&src_q->done_lock, flags); 924 910 925 911 spin_lock_irqsave(&dst_q->done_lock, flags); 926 - if (!list_empty(&dst_q->done_list)) 927 - dst_vb = list_first_entry(&dst_q->done_list, struct vb2_buffer, 928 - done_entry); 929 - if (dst_vb && (dst_vb->state == VB2_BUF_STATE_DONE 930 - || dst_vb->state == VB2_BUF_STATE_ERROR)) 912 + /* 913 + * If the last buffer was dequeued from the capture queue, signal 914 + * userspace. DQBUF(CAPTURE) will return -EPIPE. 915 + */ 916 + if (!list_empty(&dst_q->done_list) || dst_q->last_buffer_dequeued) 931 917 rc |= EPOLLIN | EPOLLRDNORM; 932 918 spin_unlock_irqrestore(&dst_q->done_lock, flags); 933 919