From patchwork Wed Oct 26 12:06:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp227105wru; Wed, 26 Oct 2022 05:10:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vGHYM27Cc7eq/f7dcGR6WnAAASA+Ecus6y1it3Aw4E1/Fx+kMhFNYLAfyPn+hSrxefqYg X-Received: by 2002:a05:6402:2546:b0:45d:8bff:7afc with SMTP id l6-20020a056402254600b0045d8bff7afcmr39959052edb.302.1666786251210; Wed, 26 Oct 2022 05:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666786251; cv=none; d=google.com; s=arc-20160816; b=eGg4JLsX0XNjWkaINvrNw+/IwAIOK4L3AtXaxYQNtC7jl8gZ9BFJqAzSF55qNeDU0X Kl0NE/YwKwqRs8wnfO8WKaMF83i0KAB8C/3yITwXXBxVtpFGn1U94cYXvImyTYBJKQml rQdy9GuwSqdp+sQ/zlWrrcmmwXfqqLuxRHItnDm3L12oSNhmjhDaL+4gkGR+ufECFgNj EjRvni9L+xGWsqF9xV75kGDLZKUpaw3R5caADWozsRIyMrFD1bzp+zlcEQScqYsC9ivX cpY7hFlr3eTDWuPn6Wo2DT/MxXV64ZayJLijHYWlHaBiHgadLgZS3gdEfOBUyDltgUl9 PhRg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds9-20020a170907724900b0077547abf08fsi6408527ejc.169.2022.10.26.05.10.25; Wed, 26 Oct 2022 05:10:51 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747752060099739297?= X-GMAIL-MSGID: =?utf-8?q?1747752060099739297?= 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;