From patchwork Mon Oct 30 20:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avichal Rakesh X-Patchwork-Id: 159870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2485400vqb; Mon, 30 Oct 2023 13:23:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFR536TXwVPmMAF0m1JRH/nrdHb7n6RtGABJsP9ZiYYKVQUCNbtIft+5N76ByUecETgBkn4 X-Received: by 2002:a05:6a20:8e22:b0:15e:9923:3e35 with SMTP id y34-20020a056a208e2200b0015e99233e35mr815942pzj.19.1698697397987; Mon, 30 Oct 2023 13:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698697397; cv=none; d=google.com; s=arc-20160816; b=BdlRr7JAS0H7IsVTeVA9WBdYJG8CEF9ot/BkzJH61gOQGh+bL3pXkSc2KYFDiztfu4 2uJcR2y5PEFCnbQltugwZ0YtB6Vw9JNG1b90MjA/tiZEyuUg8ffn2PbdtX58CG+5TwgX dzalgB0N4mSNQ65ooT+NYxUubEcYCMhGMZKFaK8Hr7/MPp5GuIqAV4azG4HOq+2veIPV NU9ZU8Kasq7tl5BFblueHnxpAskYtkYVQeAUkVMh1uDqBjcUnd86aAmqNjnJyrQLcCPw hpWnEoxo8hFCbEm0DTXVYJHa4l+Fs30m0/89AfPW8k+1E1LI9+pkwWL1hPwyX/vA8R36 2fUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=ObSidP8JTCZls9mTLBjvE7k31kuLSrW0wzxXXc7FEEI=; fh=p+LYTnSpNzrqEe7IwOmRmqfbsNd6xnlNPhpiE7PelQI=; b=qwtLe3GKOro0ooTRoVkMarhEf1mYS9tx6FtPYDsLF0cA3f+wYryOA3lIgE6g7GzWWn k4uR1mgvolRY9bMeO1L9WkDTo6mPw8UcErhAvpuY86klBoMTntACNYtBK1QJxwOnbdTl U3FJr5ZAG6bNqxqbjaR7D7GCULbt6fZuHx3Aff7jKDZJU3mZeitMKHTuh/riPk5xmbMd YKkCOiGY4f9wUNGuWwPAj70Gy657R48aPS9YSnJKGdWUZOqlDucscp3pnUk/hEeVjbU9 TxtgVkRPcPbDm2Xs5ypzhppTs6jE710QObnWw+19YlPHpR6TGGWSWq/zQHDG7ER7amnM 966g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zQcl83m0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u11-20020a6540cb000000b005b96dd108aasi3303674pgp.876.2023.10.30.13.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 13:23:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zQcl83m0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id AB85F80488C4; Mon, 30 Oct 2023 13:23:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbjJ3UWy (ORCPT + 32 others); Mon, 30 Oct 2023 16:22:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbjJ3UWv (ORCPT ); Mon, 30 Oct 2023 16:22:51 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCBB6109 for ; Mon, 30 Oct 2023 13:22:42 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da307fb7752so1931221276.0 for ; Mon, 30 Oct 2023 13:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698697362; x=1699302162; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ObSidP8JTCZls9mTLBjvE7k31kuLSrW0wzxXXc7FEEI=; b=zQcl83m0FC2L6KsVk+LJoeCOOH38nj3xIEh0Vvb8feJl2mG8AyGai9LqX2RyTweo4K m9sgzHuRR3BQ6ZhiKO/VFP4AYbxcEtUxVJBMyKsDOxhPtuIdxOBV9n+kOW7cqF1r+nLg h98s4N4dLmmbpczrd4e89+uMbx69OKXpOsHs0pl+K+S9VS63tuFYKZ829kH+vPTzrvvw 54DkvsjpW7pQg2gqnUoD9WB5faYhJkNS0tARdK9hEruhzIHLWzBmnsFuLdFcJH2rDYyI Ns4VTnQ/iGALyLNmbTMwVkD+mJQxZD4kuIKpmfSx3qszrYWHpJjw50GVrOZhEzCySsW5 DETw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698697362; x=1699302162; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ObSidP8JTCZls9mTLBjvE7k31kuLSrW0wzxXXc7FEEI=; b=beWfiPqrRs7UmCV7yOTWLLE+YTR9s3VrY/Uw07yyfk1SGCIRxUK1vLUyIlASXIC7X5 p2pq1THgOvzOdid8M7s8yU0d/OqQLKdJ0U01vX1VC+Xd6kzNFj6ydi5mY9HgLKpeWaJ7 9ql7H0sAwtRiujhiPQT9ntYHc1Sf6WfR1yVDb4PKtr+dfNB6iyWMm7WOqHkdA4Fz7eLu /AIgqVmyXapfi90BSTRIn5+D9P8ZwxuWBlYC9/WkVLHk6nxxZfynyWn7A536IC3QLjtT ALxD0m0bsyEf/cgFlTwQMfegIa78R8OcMTbgHr3tKAHrRuf/RepM29fVN4Lkwqe1hPRk zYIA== X-Gm-Message-State: AOJu0Yy3SiiPiaPHv4K4CFpDR7ngEOR0K0KzGiRkb0SXTLPX5vgTuOaN /tL0R/fuTm1qaeKQ6UJUuscF3BQ3Dewy X-Received: from hi-h2o-specialist.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3cef]) (user=arakesh job=sendgmr) by 2002:a25:cf09:0:b0:d90:e642:d9fc with SMTP id f9-20020a25cf09000000b00d90e642d9fcmr208026ybg.6.1698697361861; Mon, 30 Oct 2023 13:22:41 -0700 (PDT) Date: Mon, 30 Oct 2023 13:22:30 -0700 In-Reply-To: <20231030202231.3263253-1-arakesh@google.com> Mime-Version: 1.0 References: <73309396-3856-43a2-9a6f-81a40ed594db@google.com> <20231030202231.3263253-1-arakesh@google.com> X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231030202231.3263253-3-arakesh@google.com> Subject: [PATCH v10 3/4] usb: gadget: uvc: move video disable logic to its own function From: Avichal Rakesh To: arakesh@google.com, dan.scally@ideasonboard.com Cc: etalvala@google.com, gregkh@linuxfoundation.org, jchowdhary@google.com, laurent.pinchart@ideasonboard.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, m.grzeschik@pengutronix.de X-Spam-Status: No, score=-5.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 30 Oct 2023 13:23:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780941381866226962 X-GMAIL-MSGID: 1781213322972005030 This patch refactors the video disable logic in uvcg_video_enable into its own separate function 'uvcg_video_disable'. This function is now used anywhere uvcg_video_enable(video, 0) was used. Reviewed-by: Daniel Scally Suggested-by: Michael Grzeschik Signed-off-by: Avichal Rakesh --- v6 : Introduced this patch to make the next one easier to review v6 -> v7 : Add Suggested-by v7 -> v8 : No change. Getting back in review queue v8 -> v9 : Call uvcg_video_disable directly instead of uvcg_video_enable(video, 0) v9 -> v10: Rebase to ToT (usb-next) drivers/usb/gadget/function/uvc_v4l2.c | 6 ++-- drivers/usb/gadget/function/uvc_video.c | 40 ++++++++++++++++--------- drivers/usb/gadget/function/uvc_video.h | 3 +- 3 files changed, 31 insertions(+), 18 deletions(-) -- 2.42.0.820.g83a721a137-goog diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c index 7cb8d027ff0c..904dd283cbf7 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c @@ -443,7 +443,7 @@ uvc_v4l2_streamon(struct file *file, void *fh, enum v4l2_buf_type type) return -EINVAL; /* Enable UVC video. */ - ret = uvcg_video_enable(video, 1); + ret = uvcg_video_enable(video); if (ret < 0) return ret; @@ -469,7 +469,7 @@ uvc_v4l2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type) return -EINVAL; uvc->state = UVC_STATE_CONNECTED; - ret = uvcg_video_enable(video, 0); + ret = uvcg_video_disable(video); if (ret < 0) return ret; @@ -515,7 +515,7 @@ static void uvc_v4l2_disable(struct uvc_device *uvc) if (uvc->state == UVC_STATE_STREAMING) uvc->state = UVC_STATE_CONNECTED; - uvcg_video_enable(&uvc->video, 0); + uvcg_video_disable(&uvc->video); uvcg_free_buffers(&uvc->video.queue); uvc->func_connected = false; wake_up_interruptible(&uvc->func_connected_queue); diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index 1619f9664748..c3e8c48f46a9 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -493,31 +493,43 @@ static void uvcg_video_pump(struct work_struct *work) } /* - * Enable or disable the video stream. + * Disable the video stream */ -int uvcg_video_enable(struct uvc_video *video, int enable) +int +uvcg_video_disable(struct uvc_video *video) { - int ret; struct uvc_request *ureq; if (video->ep == NULL) { uvcg_info(&video->uvc->func, - "Video enable failed, device is uninitialized.\n"); + "Video disable failed, device is uninitialized.\n"); return -ENODEV; } - if (!enable) { - cancel_work_sync(&video->pump); - uvcg_queue_cancel(&video->queue, 0); + cancel_work_sync(&video->pump); + uvcg_queue_cancel(&video->queue, 0); - list_for_each_entry(ureq, &video->ureqs, list) { - if (ureq->req) - usb_ep_dequeue(video->ep, ureq->req); - } + list_for_each_entry(ureq, &video->ureqs, list) { + if (ureq->req) + usb_ep_dequeue(video->ep, ureq->req); + } - uvc_video_free_requests(video); - uvcg_queue_enable(&video->queue, 0); - return 0; + uvc_video_free_requests(video); + uvcg_queue_enable(&video->queue, 0); + return 0; +} + +/* + * Enable the video stream. + */ +int uvcg_video_enable(struct uvc_video *video) +{ + int ret; + + if (video->ep == NULL) { + uvcg_info(&video->uvc->func, + "Video enable failed, device is uninitialized.\n"); + return -ENODEV; } if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) diff --git a/drivers/usb/gadget/function/uvc_video.h b/drivers/usb/gadget/function/uvc_video.h index 03adeefa343b..8ef6259741f1 100644 --- a/drivers/usb/gadget/function/uvc_video.h +++ b/drivers/usb/gadget/function/uvc_video.h @@ -14,7 +14,8 @@ struct uvc_video; -int uvcg_video_enable(struct uvc_video *video, int enable); +int uvcg_video_enable(struct uvc_video *video); +int uvcg_video_disable(struct uvc_video *video); int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc);