Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp641350rwi; Wed, 26 Oct 2022 05:35:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6YwOa5e83bNqR3X3mK/Olc+WT8w1yO5/sUCVQ+/uR5MtP4kYW/bklZQmLs6FYevWAwDxLz X-Received: by 2002:a50:fc03:0:b0:461:5d8d:5811 with SMTP id i3-20020a50fc03000000b004615d8d5811mr24612319edr.351.1666787728928; Wed, 26 Oct 2022 05:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666787728; cv=none; d=google.com; s=arc-20160816; b=F8IlX/hXm1ws0b2U19B9o0XBE+/FnXl3AWXVCYIErXkQHE8PMWmh5JuxzugfIIl35e HX+edcDq79L0pXudW9UjiEIqsNv+0FVb1vrMshCHlI4D+Grf42UAw2iIxALwpHCYL6us jNqU64KcWLae7Bjo/UtCZcYDeRsfmLUlu+VwaKnitW4Isi9bmZbZfsitN+9H5yDQr4kQ urndrgiWpz/D22ernG93R+hKTr59g9nVMkhtpfMTBeXtZpc7qSE6oGt0jqX7KSwxZVs4 plClKKTjwwQ9GgpkvHTF09m8+uxTozFdyUYzNG/IzLryun+n6v7KS24LJOe+sJ8EK6y+ KHIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=fw978dyctQKYz24O/MzUIY5FG9WdD7MbzKHKlFXG3Qw=; b=mKEc8nV3fHa3APrDfappLibdUdIYYFap39OuEaezV09HyKuQQJMc86K/U3Hd4ZCklT +kRq+AE9AqOgcDvkAdodQb9YV5SnzogWp0IX0Dbz9G4KfR8PXHZYf0GwiwS4g9yil66Y 1OVJQybN35jXdDD3M0VYzpSNrUD9VbFvuHV8QL/+DZQGC1VUNfA2JnC4HmmFmdjEXXRU J1Q8KuZyN01+eFJ700sjzgdZqGpWTh0cv+mS1GWaPp7ck4JkFc8loZhGi/qDpYdXoFyU hfHomk4QxrOJucZZe+rIrtVzUP/1Xd7KDjr04C35zrDwEzCbkbwQV9cjxeu03ggp7ZUd ymzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RNEWO8yC; 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 cr18-20020a170906d55200b00781d6cda765si6237251ejc.913.2022.10.26.05.35.01; Wed, 26 Oct 2022 05:35:28 -0700 (PDT) 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=RNEWO8yC; 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 S233698AbiJZMGo (ORCPT + 99 others); Wed, 26 Oct 2022 08:06:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233664AbiJZMGg (ORCPT ); Wed, 26 Oct 2022 08:06:36 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 384248FD5C for ; Wed, 26 Oct 2022 05:06:35 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id i21so19997308edj.10 for ; Wed, 26 Oct 2022 05:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fw978dyctQKYz24O/MzUIY5FG9WdD7MbzKHKlFXG3Qw=; b=RNEWO8yCqIDykMwTYHMv+kJVII6rNKH4/P/QPL/q6horof/ZVy7k5E+Ma6ijN5FZT7 15Hz+LQn182NqAizezzVe12b8E2TcHlZ8UUeH5FyDycQZSMucG2V5Gr3cU+9JEvtJGZp tEzlJwyl/DwxrWQSyYJ5ns/LBFAR1kaoiyTlM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fw978dyctQKYz24O/MzUIY5FG9WdD7MbzKHKlFXG3Qw=; b=eKxQjG6z+iQE1lfkexoJ9V9sasY2zZMyvekwv0TTbFl+RZHc+Mo4e1FWF2VNB1uO1z O0gcLDE3CBEJpjUtiBtvpt1sQHXE/127PdSMTeC00+mb24Unky2UVPBuA/jjYLiVBTQY h20dVDyJrt7Ees78nPeqNbn7/2pTijPhl5I8pWooEA5X6OV8h63xdAkiyiPb5QlJJw+/ tq3JJzuqqQceJnNfT+oaYnYUnRbGr7Q+DgEJieFcawq7OqltR5ffE6BgkqJPXUeqY1go sM+AHsSx7k8hXQve8oWWFy+1PQ8IsLMxJk8QDpu/qGHypeyQtYrBNIzO7UJ8DH6wOUzj rVAQ== X-Gm-Message-State: ACrzQf34h15zUViZDluoEEIbre7p3cwd0SlNr4smFAdr+4IyJlmpDqa2 NFxsw402MldubgSB8wDpneJFBg== X-Received: by 2002:a05:6402:550e:b0:456:f79f:2bed with SMTP id fi14-20020a056402550e00b00456f79f2bedmr41217834edb.106.1666785993850; Wed, 26 Oct 2022 05:06:33 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:b47a:bedd:2941:1e3f]) by smtp.gmail.com with ESMTPSA id y18-20020a17090668d200b0079e11b8e891sm2892546ejr.125.2022.10.26.05.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 05:06:33 -0700 (PDT) From: Ricardo Ribalda Date: Wed, 26 Oct 2022 14:06:06 +0200 Subject: [PATCH v3 1/7] media: uvcvideo: Refactor streamon/streamoff MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20220920-resend-powersave-v3-1-c47856d8757e@chromium.org> References: <20220920-resend-powersave-v3-0-c47856d8757e@chromium.org> In-Reply-To: <20220920-resend-powersave-v3-0-c47856d8757e@chromium.org> To: Mauro Carvalho Chehab Cc: Tomasz Figa , Ricardo Ribalda , Guenter Roeck , Max Staudt , linux-kernel@vger.kernel.org, Alan Stern , Hans Verkuil , Laurent Pinchart , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1977; i=ribalda@chromium.org; h=from:subject:message-id; bh=NB6aEyZdAyQsktG3au/4ny2fc8G0li6jsr2nryh8gpk=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjWSK7fJwo06bKVIb5CIAm+Y73zwAAOjAjBzBn92Px 23qElF2JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY1kiuwAKCRDRN9E+zzrEiISqEA CbHxpyUE2B5x4mM0Jf0jPg9SdgW+xI++1ntCUxoIRnXqxPMmXIvKLdeSh84cYwk0Tba8PEn987ucuX cOHnIiROzdBvCHx8/sos6Xwq27u15CW+h57TKUu8DMiZsns2Cs/RZxt429+WvWcBaoK1ZxKS9//yoU HG41ExZRMxLuM1CicJfeRuX5Hjct00ITxOEpnMTMKgTEzdhBabLPZi3AhsGOylblf/VlZetxkZJo+d XjZlh3t52MfQ08uePxFSFVk1/HcK2s3ameYdCM+/PUBk1mkKrfLyqwrPGvMle+Dos+8nZKpw1hMFxH Tt8SUkAvIVFbyic4pi40EVk4aEQc4wQ2UcRn9MdniJd4TBgzrvoYgrF0xNnWGEiV7CCrPMQjDJOLSl KFs3drtskxxw/rwCbY/pVbeeBOua2fLa9rVpEsmifcybknI0Ycr48fZdLa7VZ4JztxYpBJN8PbMWsa /QhxRRqlkzNVa1CnjZaQrY6WCMp0rjeePxnlxrCTI4eK9T5bqlYHjOvnB8m9hlMmEU96XaO72ExYyp N+laziNK4zI/MqMDrIoV33iuGAqOyAWtMkpMZXcEzH2wxiIlxLSPp9osWvIXPu4uGYnVNd/VMI5mbH 6EF/xKxx7/oduzVEpAab17WU+7T/CGfN2KIXkNNMXG4i2PLvvDwIF1XuE1eA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f4d4c33b6dfb..1389a87b8ae1 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -840,13 +840,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; @@ -857,15 +863,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 df93db259312..45310f55475f 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -581,6 +581,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; -- b4 0.11.0-dev-d93f8