Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5404947pxb; Mon, 7 Feb 2022 00:57:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBR2R4Ywv2quMzaqLzwXc8SsXd97ZR47pQBp9EP5VQvrvblQ3acZRS8WCsDGcdQE4XMJPF X-Received: by 2002:a17:902:694c:: with SMTP id k12mr15924353plt.98.1644224267606; Mon, 07 Feb 2022 00:57:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644224267; cv=none; d=google.com; s=arc-20160816; b=CyRtlIZmdGqHTAyIkOZlDWx27XYnzPIQTKoKXd+UWXicB98x/ax9tFVeO99JZxL5ed xKwVj8apIKUpdSUbLBd5As62vGyYZOrNMFpsY2QCwNqyp4Ib2eAT0kkV+MaalUCXuhz7 dvlEdZqYwhSiY6KNJjc6oc57bbm1F7IG/x67IcnYW9oUAknyLXDQk7upAA4jx7IQV++B HRz8HTTyj8pVNJNEZA+VXj8utXenCDvURxTV15MIh3uuavAvsCf0jvg06rLIvzxq49Of +R19ZYwoySFVQ10DYoyDh5MMXvhi3P+hodRhW2b9BaYvPSU4OEl+YFc+8mIU3ElnM86W 1ZUw== 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=V/+oTJIUco9iSDLcoK98xrLmbOde1duXTh41+KP2gLs=; b=J5Wa10bRGSasmQhygwIAExmrH657G7eMsUe4sR175GJvhGGuBJWFCQptQG7tAS9W34 E7Dbxd/bBJk1JtQ9Gt/CnhWNmwmaBB3wmkxl6767vbxstLkpRsvO2byYVVCo3KozitD7 ZA4992b3xsojWuIamXaeatkYt+gV9JCM0PptDKbq2DHsGpgRKVWIMf2KsPSBgmqIcDJk Crp3GtsagPCSdsTrn0RViOGqaz6OQijIRuZ61gfek43kfzNVCgqOrYYJCKP9Zj3NhVAo pgCqYG0hAOZrk4HuBif1feWExGn1CSY4iR26qwRN6kCss52XuL9zbtze/pOh/Ll5CAaB ACwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AfKsYQsy; 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 e16si2551859plx.445.2022.02.07.00.57.34; Mon, 07 Feb 2022 00:57:47 -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=AfKsYQsy; 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 S1376775AbiBDRHw (ORCPT + 99 others); Fri, 4 Feb 2022 12:07:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234538AbiBDRHu (ORCPT ); Fri, 4 Feb 2022 12:07:50 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94487C06173E for ; Fri, 4 Feb 2022 09:07:49 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id u24so14251754eds.11 for ; Fri, 04 Feb 2022 09:07:49 -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=V/+oTJIUco9iSDLcoK98xrLmbOde1duXTh41+KP2gLs=; b=AfKsYQsyJpMcrd1jqKkHQfjmdoeQafRrchHinCqr0c9erBvsf2GDYR1pr6cHx3Mqkz UWxL0AmYbdk7JFqLTXISWU9E9x7fd4tXv1eMj3ftrowCfuKTF2nlvDOaj0/3pskPkbj5 0H740MDD8/NP0ahT4GIA5iRI1O33dlHbVfnrU= 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=V/+oTJIUco9iSDLcoK98xrLmbOde1duXTh41+KP2gLs=; b=354x5NMI9nLaGKCmOPDIBqMhIhPooP5bie4jpG/gEkK/qSVJwXRSEyTdDukhhYdcba ykPnBoMcnVcNEPqGmvkVnHoaMpRWYPZPdM9r1hDLQ+SQYOaLl4MHoHWZjS2E9vEUsvK5 eh0VY6Q37AljZGVe4nSt6tvB5N2TTOOXMhDwK/YudJWWGPFn9q8ivE32dRLsafulw+bM exlx8r5O3AnnPgcq3r1W5rKHHuTbSELCw72Stq+Lx0MX+Oe1ybCufqmbUhTI8OymoqGR qf+21o7ZwqQBO4/UT7VMWrZRZRQOcjQcLBzFW3MiATtHqYy88b5TpvqZoQZdLXJ1WM8b vNCg== X-Gm-Message-State: AOAM533ClSPMH9ZiJgRByvakDwVIsuJ5GaQXgUN2LLEDcLeaaluXs+wQ bmEtCBjxi2iZu5zKkKbyDYBQhA== X-Received: by 2002:a50:9555:: with SMTP id v21mr72899eda.214.1643994468214; Fri, 04 Feb 2022 09:07:48 -0800 (PST) Received: from alco.lan (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id gv36sm840753ejc.94.2022.02.04.09.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 09:07:47 -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 v4 2/3] media: uvcvideo: Refactor streamon/streamoff Date: Fri, 4 Feb 2022 18:07:44 +0100 Message-Id: <20220204170745.1269482-2-ribalda@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220204170745.1269482-1-ribalda@chromium.org> References: <20220204170745.1269482-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. 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