From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Guenter Roeck <linux@roeck-us.net>,
Tomasz Figa <tfiga@chromium.org>,
Alan Stern <stern@rowland.harvard.edu>,
linux-kernel@vger.kernel.org, Max Staudt <mstaudt@chromium.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Yunke Cao <yunkec@chromium.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>,
linux-media@vger.kernel.org
Subject: Re: [PATCH v5 1/2] media: uvcvideo: Refactor streamon/streamoff
Date: Tue, 27 Dec 2022 16:49:07 +0200 [thread overview]
Message-ID: <Y6sF40Nx6RPIaFcQ@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20220920-resend-powersave-v5-1-692e6df6c1e2@chromium.org>
Hi Ricardo,
Thank you for the patch.
On Tue, Dec 06, 2022 at 03:06:55PM +0100, Ricardo Ribalda wrote:
> Add a new variable to handle the streaming state and handle the
> streamoff errors, that were not handled before.
>
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Max Staudt <mstaudt@chromium.org>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> 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 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;
This isn't needed, uvc_queue_streamon() calls vb2_streamon(), which
returns an error if the queue is already streaming.
> ret = uvc_queue_streamon(&stream->queue, type);
> + handle->is_streaming = !ret;
You can just turn this into
if (!ret)
handle->is_streaming = true;
and drop all other changes to this function.
> +
> +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;
More than unneeded, this is wrong. Calling VIDIOC_STREAMOFF on a queue
that is not streaming is a valid use case, it's the only way to release
buffers that have been queued to the device. vb2_core_streamoff()
handles this correctly. You should drop this check.
> + ret = uvc_queue_streamoff(&stream->queue, type);
> + handle->is_streaming = !!ret;
And turn this into
if (!ret)
handle->is_streaming = false;
and drop all other changes to this function.
> +
> +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..0d9f335053b8 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -584,6 +584,7 @@ struct uvc_fh {
> struct uvc_video_chain *chain;
> struct uvc_streaming *stream;
> enum uvc_handle_state state;
> + bool is_streaming;
> };
>
> struct uvc_driver {
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2022-12-27 14:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-06 14:06 [PATCH v5 0/2] media: uvcvideo: Implement granular power management Ricardo Ribalda
2022-12-06 14:06 ` [PATCH v5 1/2] media: uvcvideo: Refactor streamon/streamoff Ricardo Ribalda
2022-12-12 1:15 ` Sergey Senozhatsky
2022-12-27 14:49 ` Laurent Pinchart [this message]
2022-12-06 14:06 ` [PATCH v5 2/2] media: uvcvideo: Do power management granularly Ricardo Ribalda
2022-12-12 2:59 ` Sergey Senozhatsky
2022-12-27 23:34 ` Laurent Pinchart
2022-12-27 23:48 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y6sF40Nx6RPIaFcQ@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mchehab@kernel.org \
--cc=mstaudt@chromium.org \
--cc=ribalda@chromium.org \
--cc=senozhatsky@chromium.org \
--cc=stern@rowland.harvard.edu \
--cc=tfiga@chromium.org \
--cc=yunkec@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.