Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp875293pxb; Fri, 13 Aug 2021 08:13:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCOxdxCoS7Tl1C0ws11/zAgndHPdQbe2v+Uu2FzlvZTGErzPQEZ+qQ8zMYL97ZYddW04Jx X-Received: by 2002:aa7:d54b:: with SMTP id u11mr3681587edr.160.1628867594859; Fri, 13 Aug 2021 08:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867594; cv=none; d=google.com; s=arc-20160816; b=NNBYSFky8YmP83YdOPNUO3PariW6MYEThvgYYbiMjilOj4ckm30RpDJUqwcOkqiKh9 YtiQfySju3w2ETswbXaGIA0NELae2j8qmkyrQ7+pVmUfwar+MuXdSpHo/2VeiLHwlipW ysb+4qYnkCc66oM2J3MAjYR7QPxcEVVcj5EEgZc2bfD8Zy6gDng/H95H0NIxm8rucgjK ELSTnAdaN1TMEuctSQb6Evb3Z8KOeEcICmE5xpR0MVPWqfo38jCDYjAcDotqUPNfKoij 5Wce3nOSU7SgOw8fYp0e+pgpMcRxEeG8UuYVzFhUcAUarW6/sbt+uQZkKGI9kj070hf5 yJ4g== 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=FSPts93/bKWuh+nYEGexia361vayZSqqL3oSUZnxb7E=; b=ILSr36xQYBV74FJxsot4d6FvJJW6JJNHfrOATkTuM9v7MbHCQXa0Yc89WW8+U7wx4/ ENfK7Ky9MCAFDEpKSW0C+qlk8z9+NuyrBCMjeBIAqAOATl+2KjjebLlL3sRViCg7Qoum fRbq/zPfuu9k0xKmkR5rneKqlkk+52m/D8jV8AVOy6d4CYYgEdwCkSV53NEDeblzNV3N gHhC1x423l5xa2hkgLg3kgBXA5TUXw2b0EpIH0uBOlVkaNMtmaQa7hegsWKF73FnnY9v ehUavbUq7n6azRZh6jqQHAibYIm0zN4PEwb1S2OdWJz7TsXr3xIrI1Bo1vHoGTjQ+M5D DwEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GCLcvMRg; 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 c26si1901190ejx.235.2021.08.13.08.12.48; Fri, 13 Aug 2021 08:13:14 -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=GCLcvMRg; 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 S241638AbhHMPKp (ORCPT + 99 others); Fri, 13 Aug 2021 11:10:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:52610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241491AbhHMPKP (ORCPT ); Fri, 13 Aug 2021 11:10:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F075A6109D; Fri, 13 Aug 2021 15:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867388; bh=dbdpBBFRRzf13jbm/8FS7yEMCQC+VVBhsWAdwznpnhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GCLcvMRg+2NycGmVgOLSx3nar0pM7zmqV/Vhdss7TXeusfxCs5lvDdqtzQNmNz1gh nS8jje50TsSJCwbTe30pkuENPxZxhVW1g1EfD2QsKDlFZqZ2P0yQJ2BG3u0Z2k93QT T7jbc/SkQ0bO8oVDO5KpI8MJmwk/JvRRXlMZmAsY= 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.9 03/30] media: videobuf2-core: dequeue if start_streaming fails Date: Fri, 13 Aug 2021 17:06:31 +0200 Message-Id: <20210813150522.556786043@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150522.445553924@linuxfoundation.org> References: <20210813150522.445553924@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 b1a4d4e2341b..3ac9f7260e72 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -1370,6 +1370,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) { @@ -1399,6 +1400,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; @@ -1429,8 +1431,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