mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Subject: Re: [PATCH v3 1/6] media: uvcvideo: Keep streaming state in the file handle
Date: Sun, 23 Feb 2025 17:46:17 +0200	[thread overview]
Message-ID: <20250223154617.GB27463@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20250206-uvc-granpower-ng-v3-1-32d0d7b0c5d8@chromium.org>

Hi Ricardo,

Thank you for the patch.

On Thu, Feb 06, 2025 at 07:47:00PM +0000, Ricardo Ribalda wrote:
> Add a variable in the file handle state to figure out if a camera is in
> the streaming state or not.

s/\n/ / (and reflow) or s/$/\n/ depending on what you meant.

> This variable will be used in the future for power management policies.
> 
> Now that we are at it, make use of guards to simplify the code.
> 
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  drivers/media/usb/uvc/uvc_v4l2.c | 15 +++++++++++----
>  drivers/media/usb/uvc/uvcvideo.h |  1 +
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index 93c6cdb23881..856eaa23e703 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -835,11 +835,17 @@ static int uvc_ioctl_streamon(struct file *file, void *fh,
>  	if (!uvc_has_privileges(handle))
>  		return -EBUSY;
>  
> -	mutex_lock(&stream->mutex);
> +	guard(mutex)(&stream->mutex);
> +
> +	if (handle->is_streaming)
> +		return 0;
> +
>  	ret = uvc_queue_streamon(&stream->queue, type);
> -	mutex_unlock(&stream->mutex);
> +	if (!ret)
> +		handle->is_streaming = true;
>  
>  	return ret;

Now that you use a mutex guard, you can write

	if (ret)
		return ret;

	handle->is_streaming = true;
	return 0;

apart from that,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +
>  }
>  
>  static int uvc_ioctl_streamoff(struct file *file, void *fh,
> @@ -851,9 +857,10 @@ static int uvc_ioctl_streamoff(struct file *file, void *fh,
>  	if (!uvc_has_privileges(handle))
>  		return -EBUSY;
>  
> -	mutex_lock(&stream->mutex);
> +	guard(mutex)(&stream->mutex);
> +
>  	uvc_queue_streamoff(&stream->queue, type);
> -	mutex_unlock(&stream->mutex);
> +	handle->is_streaming = false;
>  
>  	return 0;
>  }
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 5e388f05f3fc..bc87e1f2c669 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -618,6 +618,7 @@ struct uvc_fh {
>  	struct uvc_streaming *stream;
>  	enum uvc_handle_state state;
>  	unsigned int pending_async_ctrls;
> +	bool is_streaming;
>  };
>  
>  struct uvc_driver {

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2025-02-23 15:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 19:46 [PATCH v3 0/6] media: uvcvideo: Implement Granular Power Saving Ricardo Ribalda
2025-02-06 19:47 ` [PATCH v3 1/6] media: uvcvideo: Keep streaming state in the file handle Ricardo Ribalda
2025-02-23 15:46   ` Laurent Pinchart [this message]
2025-02-06 19:47 ` [PATCH v3 2/6] media: uvcvideo: Move usb_autopm_(get|put)_interface to status_get Ricardo Ribalda
2025-02-23 16:05   ` Laurent Pinchart
2025-02-06 19:47 ` [PATCH v3 3/6] media: uvcvideo: Add a uvc_status guard Ricardo Ribalda
2025-02-23 16:06   ` Laurent Pinchart
2025-02-06 19:47 ` [PATCH v3 4/6] media: uvcvideo: Increase/decrease the PM counter per IOCTL Ricardo Ribalda
2025-02-23 16:55   ` Laurent Pinchart
2025-02-06 19:47 ` [PATCH v3 5/6] media: uvcvideo: Make power management granular Ricardo Ribalda
2025-02-06 19:47 ` [PATCH v3 6/6] media: uvcvideo: Do not turn on the camera for some ioctls Ricardo Ribalda

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=20250223154617.GB27463@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=guennadi.liakhovetski@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab+samsung@kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®