Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3757284pxt; Tue, 10 Aug 2021 10:36:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzAIixCpXslPXFMebgsf/KI/DEI9oylRWtK9YtBIoRVfC61T66352vH3Yh15QB2O6oZQHo X-Received: by 2002:a05:6402:40c7:: with SMTP id z7mr6135542edb.193.1628616971716; Tue, 10 Aug 2021 10:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628616971; cv=none; d=google.com; s=arc-20160816; b=KLoDVGgB/b/KrVATAxvbEjn1V3tEj27KM0QHDXpQiMtPMWRna5xQ1ea8pl1BSV3eRb hvLxJp3bQUWJtTZYsH90vlbbLwPUnKwfHrJ+ddCztr+3vXtoO4PzDeALLKYc5FEXR+mi eSnB5j2o5PYXCfFyiR7+5sflzFyxSnPLXYdjkafRd+1X5j3rZRb+PHRd9xmyPiV9SDyX ve+5XYgGOrdU8l70mMMHKgz2EDdn48jo/eNVJbAUgqC1teb0vWwva9HGIe51vjCuCi+j EwkD7tbZ1MImS27PGEXwrvtmRJtdLSY8C1uKIEwhZsRUaZsaA8rQ4fy4sfwjGAnHlkHM BQoA== 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=aZEFImB4+MLWflSDIAjCo4xTDdzmlSYDIdNq5fnEYl0=; b=T/XeTcTFdxvWGRWRdRbeMCv25mWqG4oHmvCi/T8bGRpGQ2ZCWleNx8lxHgsmiO0qA7 yYUGBzqzU+3i26YfVEsHSjq3zXuuQUBM+Jy1S7FzYkbeWZhKFqL1KVAzdbubTonmLseF lBUsE2NAjB82ky3IzLIXneLTWBnvlOdnhPSvrU1HU1J0kzeYsqL93hZNJijhRJBrAX3A /J+GZuZ3MaI4kb3+rauDeCHpP3+g3K0KmJgEClJ/PQsqkdyW7QuXkuNeqESkHz2+snAm 6nuXtjRfj8DIt56OTIQdFReG/Kr6KbPGMwwyWDLOg+BJay/x7eEfYd1RTzGuUoxiNQyj n45w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2bGmFQ32; 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 p5si18436987ejz.96.2021.08.10.10.35.47; Tue, 10 Aug 2021 10:36:11 -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=2bGmFQ32; 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 S232109AbhHJReA (ORCPT + 99 others); Tue, 10 Aug 2021 13:34:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:33340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232376AbhHJRdU (ORCPT ); Tue, 10 Aug 2021 13:33:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6BCEA61019; Tue, 10 Aug 2021 17:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616777; bh=LfBAgqGLSR1PVjFUV8XuubS+u6JFpS4Lyu+ltl8l8So=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2bGmFQ32FLduiydemvhk/Ng788fjVQ3zqnutIEbdV5PZo4BsXsXUamrUtFIZQBMoK /asT1aIrgK8ddHYwZZg8Vts2tFLwkR3NvASOnWNcyA2iSojT5Fya+I2xUtKKSbCl5L qwxujDwvVJit21/+h/PG6l0XaJoJyw9PHwjT8DFM= 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.19 09/54] media: videobuf2-core: dequeue if start_streaming fails Date: Tue, 10 Aug 2021 19:30:03 +0200 Message-Id: <20210810172944.494044716@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172944.179901509@linuxfoundation.org> References: <20210810172944.179901509@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/common/videobuf2/videobuf2-core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 93d250db0b6f..50015a2ea5ce 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1391,6 +1391,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) { @@ -1420,6 +1421,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; @@ -1450,8 +1452,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(2, "qbuf of buffer %d succeeded\n", vb->index); -- 2.30.2