From patchwork Tue Oct 25 14:34:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 618554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFC48C04A95 for ; Tue, 25 Oct 2022 14:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232265AbiJYOfU (ORCPT ); Tue, 25 Oct 2022 10:35:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232201AbiJYOfP (ORCPT ); Tue, 25 Oct 2022 10:35:15 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B0A8D227 for ; Tue, 25 Oct 2022 07:35:14 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id q9so13176602ejd.0 for ; Tue, 25 Oct 2022 07:35:14 -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=bmLkeE92rI1LV5eRKtnqFtVtKlsxbsg9ecVDft0DT/GIwpvbLDl01gJxig5T0jNIyd +4diSJLScqdvKuCMrCzoJ6SVfJwYuoKr3pk2VSYImmhZg3sPEgPNTlRUslJw0hjj+iVZ Bn/Frf/KpoKM7o1+hOrk1+ZKYfI3YnRw5QZ6A= 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=dMiRxFP7Lbi4IWIEXT4sewO8wbF+b7bQsAzofDsyaFtDtJIZniz2PF7vsJw1ImwRFc QvuBf1tTYvQDlzhT64ZwGLQ/i5S0/PGcZd87awDXAmvOeAxvv06NgIpWKujj3bizyY43 1S41A2/Hpx2YjJ4nWh1iXjS4j0hPOB62TWXCqvzErV9ezmJZkQsxKMqRBTm6My3gXWQg iLp/GN8xg+/fGmJyQD2NspWYBQmzp5TSNPgGZURcEAtMUefC/GTUzzmA6gP8iPaMWocC i9q9oLqfNDtSXzHA5Sh+bTS/JV2bnLpx6wzi3d6zaDgmBLHozbY6Gty13iXqf9pMNgX2 6Lmw== X-Gm-Message-State: ACrzQf1OSFompQAya+/bzmgd3m8JO70QF6A2Zno7giB2Gy8oPjitjzuE xiHbJqt05v3c+1FXsUR37s6aPw== X-Google-Smtp-Source: AMsMyM77Li5Xvdjs5rOn2zK1EnbtQexTxS7e0kamFnWqQjkI4wBzvSv9N/PFgWWQnxoEHdC0ebsEHQ== X-Received: by 2002:a17:907:c05:b0:73d:6e0a:8d22 with SMTP id ga5-20020a1709070c0500b0073d6e0a8d22mr32994041ejc.646.1666708513448; Tue, 25 Oct 2022 07:35:13 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:e6ae:c7ac:c234:953c]) by smtp.gmail.com with ESMTPSA id e9-20020a170906314900b007acd04fcedcsm631021eje.46.2022.10.25.07.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 07:35:12 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 25 Oct 2022 16:34:23 +0200 Subject: [PATCH v2 2/8] media: uvcvideo: Refactor streamon/streamoff MIME-Version: 1.0 Message-Id: <20220920-resend-powersave-v2-2-5135d1bb1c38@chromium.org> References: <20220920-resend-powersave-v2-0-5135d1bb1c38@chromium.org> In-Reply-To: <20220920-resend-powersave-v2-0-5135d1bb1c38@chromium.org> To: Mauro Carvalho Chehab Cc: Laurent Pinchart , Guenter Roeck , Max Staudt , linux-media@vger.kernel.org, Tomasz Figa , linux-kernel@vger.kernel.org, Alan Stern , Ricardo Ribalda , Hans Verkuil 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/ZANAwAKAdE30T7POsSIAcsmYgBjV/QR6p/N/GSdWGniClNtVwAPcJBAGTXLWJoRKpUt 0WA3K4yJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY1f0EQAKCRDRN9E+zzrEiOeREA CB2VW7wYO9JmilaSY15eLOYmFRdBeDHrKtiMPi7vGit/vrZQEdlX1GkhsmvhtFQOYf5X1bOWzEDFHz 39J8jZqoLIVNkQF7KiyserEfeAtCFaqOYTvNCmGuCmp1tUUTqgdPkTRDlwUOM26FfSuYhaVWcGLdGW QSEZp993O0oDkpfsmCXenx6Vitop2NCT5NOKguJqTb9nCzbp5aSQcWkKvRZmlQvCjsq/gtrViy+161 /gY254FN95KzohXog9BodoFz7nmTGWnscVRdbDsBXA7+WwwkKwMQVec35X+JFHPOywWv9SYOv6ZnXE DUBu1WYi5mqLgpQ05jBw3JPliocxdZ23k4pK05ekZuHOeRlvwlrF5PIfXPmV+5AX/5V3Z+ZD5wthHu fsLk7e+9T7E6pDPpu2DemRO9LS4INVocaafzIeqPYTXors63sWqCr+4Bbkb2CE9qU1ASM+he5ObXfg rAyBA3gQpaU+Ry6/WafZRN6s3wI/xp1XBpW69C/4moCMe9hIUlo5bSFz++ISYR92oDoRscFSH5UKYi QF/Az9KgcfKi0SoR19lfI8dEuYTp+1SfyqYfcx5zZtQsU9DXcaJ+N7IKpwyv+25MIJpsTdk9pdGyJt gWsBDMvV9C7H/vtIemgsOBpTVkq8eI7JnG++g0M7TXp7869qJxxLniTlKzOw== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 Precedence: bulk List-ID: X-Mailing-List: linux-media@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;