Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5372136pxb; Sun, 6 Feb 2022 23:58:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4EhWvU/CrBcoYFOe75OcgUEj5bYpPr42oZprm3I2yZkFT+SsiEOdMb++onDfo0/lNLb7B X-Received: by 2002:a17:907:2d29:: with SMTP id gs41mr104238ejc.14.1644220697654; Sun, 06 Feb 2022 23:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644220697; cv=none; d=google.com; s=arc-20160816; b=tHYJJknghI5DJeXQatV9myl4+XDivcqWY4JluHHfEAAzFPe71GCCJF0L6nHuO/V+Df xsRUmFugIlAshGDsKrphfb3FPPe7QwU4iHHm9F+DC8cZPODSC5oLqrFcPbxdvBWjg6m5 xVSg4fLjF/TfTNdjbbtKpGRgbGhThNO23v8/g9mGJKsHcueqIwjbU5c+T8Y3dnhPRtzD eXIcKLyq6DsVWZBtjVWTyneptwNDWLbbr0ANdzGnrT7LSj8ZLdfQ7Oe23bsKJA+RFRRA ofxdZ0hyVyWVGm0EqEFoER5pmZbZ4q9tnvfpCrQ7jMzhaTVT5C/Y4VFHe1k8eBUOzquK q+yg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=70aba+gXbkqdI4Od7Xpu39VsQQbTbunqa4tpFaQFQGU=; b=d9szSnMJB6+xXfTFkzS1Hghtc5RohXAF4bFYZBNeeVJ4nPgfHCg+O1rRle6TLR72ZZ yYl6hYKHbP4z0jThCgoU4MrEZjPTi5nFxbez0evh6MLFpPskKCxqgB84Re9B9g8G+Rq0 9NrgZec0FM07u04TpuzEbPtFgERBoalD4kOzwEmQphoKW+KqCrQoF4pVWYRGKGuxy/6f +jh2rTm5BwbXxtWgfXmvecYkzaIePgQY2rpoip8l6HZUVvqa/N3epHNziszNNnf8h7d6 tkuSXEsz9t8hix1NMij7y43Fel/BePeLz3ZEPqiPVCGVACI2cAiojFy1ICwdpQaTh600 QcOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=drCQJCor; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f26si2208314edx.209.2022.02.06.23.57.53; Sun, 06 Feb 2022 23:58:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=drCQJCor; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376792AbiBDRKw (ORCPT + 99 others); Fri, 4 Feb 2022 12:10:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376768AbiBDRKs (ORCPT ); Fri, 4 Feb 2022 12:10:48 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7972C06173D for ; Fri, 4 Feb 2022 09:10:48 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id s13so21373435ejy.3 for ; Fri, 04 Feb 2022 09:10:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=70aba+gXbkqdI4Od7Xpu39VsQQbTbunqa4tpFaQFQGU=; b=drCQJCor2IUi+p1j6BTCiIEjEdXQKPi8mTKHS63CswoGKeJlxFwpB91jTLQec3uko7 dd2BDHhgL5kqAo8DpcznfxAMnhWdxzMiHx5UTcVdDVoBhln4spp3Zc+5BaGDuwzYpS3U Ik16OgwOTIz6rcFEZ9xi03L52JAZZoZ/YYHEU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=70aba+gXbkqdI4Od7Xpu39VsQQbTbunqa4tpFaQFQGU=; b=8FetZ3N4duH+xlIklTigGZChj3RvzSZ3/k0DwUp8yP2RfrDwMBln0WwI1gQODtSgVO c208XqswDLjvgenkIpYChOOlgSICw99uLVqO6BAnTrdI1H5oxS9Yno20CMdKkBAm185R lsezShQ9oqz/ufm9nBzoLG/ap7t7nTgsGwtFAe86feYIWEIDc+/UG6qqiI+atCByaxVF qQanXPtHRiqeU/mjQYdYjSvr/pc3nMqm2Tqg+goAcjWSGZbzDxT2semNha9P/F2siLui vGVeXdFbNOxnRvybBBcQS6XKusxYj59wGitz2wZ+jKxCCGyYvPSt9is7U0dk3ab+x6IU 49FQ== X-Gm-Message-State: AOAM533BcUsIxtKClWAgEtVKBruftqlugcWFOQijQ1cNPOxdOeKb77bC zAhC89Ir9RxH9ZL6s7IjfOh7Eg== X-Received: by 2002:a17:907:2d1e:: with SMTP id gs30mr3329232ejc.14.1643994647207; Fri, 04 Feb 2022 09:10:47 -0800 (PST) Received: from alco.lan (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id bf21sm1103800edb.2.2022.02.04.09.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 09:10:46 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomasz Figa , Sergey Senozhatsky Cc: Ricardo Ribalda Subject: [PATCH v5 2/3] media: uvcvideo: Refactor streamon/streamoff Date: Fri, 4 Feb 2022 18:10:42 +0100 Message-Id: <20220204171043.1271215-2-ribalda@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220204171043.1271215-1-ribalda@chromium.org> References: <20220204171043.1271215-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new variable to handle the streaming state and handle the streamoff errors, that were not handled before. Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 19 ++++++++++++++++--- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 711556d13d03..ae1f221b2a5d 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -836,13 +836,19 @@ static int uvc_ioctl_streamon(struct file *file, void *fh, { struct uvc_fh *handle = fh; struct uvc_streaming *stream = handle->stream; - int ret; + int ret = -EBUSY; if (!uvc_has_privileges(handle)) return -EBUSY; mutex_lock(&stream->mutex); + + if (handle->is_streaming) + goto unlock; ret = uvc_queue_streamon(&stream->queue, type); + handle->is_streaming = !ret; + +unlock: mutex_unlock(&stream->mutex); return ret; @@ -853,15 +859,22 @@ static int uvc_ioctl_streamoff(struct file *file, void *fh, { struct uvc_fh *handle = fh; struct uvc_streaming *stream = handle->stream; + int ret = 0; if (!uvc_has_privileges(handle)) return -EBUSY; mutex_lock(&stream->mutex); - uvc_queue_streamoff(&stream->queue, type); + + if (!handle->is_streaming) + goto unlock; + ret = uvc_queue_streamoff(&stream->queue, type); + handle->is_streaming = !!ret; + +unlock: mutex_unlock(&stream->mutex); - return 0; + return ret; } static int uvc_ioctl_enum_input(struct file *file, void *fh, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 143230b3275b..5958b2a54dab 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -720,6 +720,7 @@ enum uvc_handle_state { struct uvc_fh { struct v4l2_fh vfh; + bool is_streaming; struct uvc_video_chain *chain; struct uvc_streaming *stream; enum uvc_handle_state state; -- 2.35.0.263.gb82422642f-goog