Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp872943pxb; Fri, 13 Aug 2021 08:10:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGJQeJQ/jPrsXeamfxgHwWQ2tMdXAI1qm9tJhRQ9ZKYaTPjHsCCrDx+y/fF+hqmcmG7t6/ X-Received: by 2002:a92:3f0b:: with SMTP id m11mr2115555ila.265.1628867441208; Fri, 13 Aug 2021 08:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867441; cv=none; d=google.com; s=arc-20160816; b=fb8h69EWw/4poPJJ5sWQgcWm2XmG4ch2tJJZ1RVVS62xp1osL5AqvfJ9xhFEDQCawJ ZaRW+ALaQ+DYrsQ1Bfe9qmUsfBvlvUVp1nFMeHu4y84XyMSnDrnSQri4eq5IN41FtDe7 zAUiIN1QoCNsJlZpHsYGWcUSXVS9IKJY/0jc3mC9kN52aYYU5DXizScAG72AZh2N7DJC H2yecAsRBdiUZESYKIMezmfo2wVq0imOwYZqdH/7iWAKRYbKumwAMmh3rSgD16wyadpy NiQR7NlwY0GgvbuaGl//4veljmu9EZ7sD3xoRwAIarIaRdMR/6FH9cLTRl5HP1d9ZLOW T8SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BHpifKLz56qXq3beZf0UP6up/8LIfqrEWkgGc6wM7TE=; b=PxVWjsI1Y1PaUCOV3z+X4T3FhDpAeQsWdfO7RN9sl//LVjSv3odkRlGUpw8JhKcJef 03TcWMQ5Oc4F3S3CakhXsrdxE+6qfF2ZdJpbntw4b1c1yYa4ql7V8FyvT5uhcUTD1YRE knGQZPObCDjd/McwTdAF2hsld4/s8WQV8LEL5KTvpLadKGkfCWyzJIhBolnvNjFBeA+B dyUTF5YTu1jDmfubYGkRGBTreURdMmeVBLmYYR2qWm4Kj24I/TlNJ6pDmr2E0VmWSboL XRwI8FCNbh/tjrmUW4S7GlB3CGtqxHI+mLL2Y8TSvsROndxZ0aDPPCIE1EE5OXPCVzSf /lrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hfxZySUY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si1715742iol.88.2021.08.13.08.10.29; Fri, 13 Aug 2021 08:10:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hfxZySUY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241307AbhHMPJm (ORCPT + 99 others); Fri, 13 Aug 2021 11:09:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:52266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241417AbhHMPJa (ORCPT ); Fri, 13 Aug 2021 11:09:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D855C6109E; Fri, 13 Aug 2021 15:09:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867343; bh=f4o1mvX6h39J6ZBNiBvDg03L4G+YikDRBmibOIXxJQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hfxZySUY18nnLbHiv8B8VuHrkHBGhRMZhwUb8h1Lt8rVMRdQJ6hqj0AyzMlN1gSb7 TSvyXKJy5aWkRoX85VENgU/dAJolCSvAqeIp9vvFtO8TFFzpVf6DLqFSpeuV0F/vU8 A4xMIzwI5+gyjp1VJLf2uCnfSGkTl22EwNMu/puw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Laurent Pinchart , Kieran Bingham , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.4 03/25] media: videobuf2-core: dequeue if start_streaming fails Date: Fri, 13 Aug 2021 17:06:27 +0200 Message-Id: <20210813150520.838261525@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150520.718161915@linuxfoundation.org> References: <20210813150520.718161915@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Verkuil [ Upstream commit c592b46907adbeb81243f7eb7a468c36692658b8 ] If a vb2_queue sets q->min_buffers_needed then when the number of queued buffers reaches q->min_buffers_needed, vb2_core_qbuf() will call the start_streaming() callback. If start_streaming() returns an error, then that error was just returned by vb2_core_qbuf(), but the buffer was still queued. However, userspace expects that if VIDIOC_QBUF fails, the buffer is returned dequeued. So if start_streaming() fails, then remove the buffer from the queue, thus avoiding this unwanted side-effect. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart Tested-by: Kieran Bingham Fixes: b3379c6201bb ("[media] vb2: only call start_streaming if sufficient buffers are queued") Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/v4l2-core/videobuf2-core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index e0041fcfa783..c1faa1332e32 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -1361,6 +1361,7 @@ static int vb2_start_streaming(struct vb2_queue *q) int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) { struct vb2_buffer *vb; + enum vb2_buffer_state orig_state; int ret; if (q->error) { @@ -1390,6 +1391,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) * Add to the queued buffers list, a buffer will stay on it until * dequeued in dqbuf. */ + orig_state = vb->state; list_add_tail(&vb->queued_entry, &q->queued_list); q->queued_count++; q->waiting_for_buffers = false; @@ -1420,8 +1422,17 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) if (q->streaming && !q->start_streaming_called && q->queued_count >= q->min_buffers_needed) { ret = vb2_start_streaming(q); - if (ret) + if (ret) { + /* + * Since vb2_core_qbuf will return with an error, + * we should return it to state DEQUEUED since + * the error indicates that the buffer wasn't queued. + */ + list_del(&vb->queued_entry); + q->queued_count--; + vb->state = orig_state; return ret; + } } dprintk(1, "qbuf of buffer %d succeeded\n", vb->index); -- 2.30.2