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 2/6] media: uvcvideo: Move usb_autopm_(get|put)_interface to status_get
Date: Sun, 23 Feb 2025 18:05:34 +0200 [thread overview]
Message-ID: <20250223160534.GC27463@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20250206-uvc-granpower-ng-v3-2-32d0d7b0c5d8@chromium.org>
Hi Ricardo,
Thank you for the patch.
On Thu, Feb 06, 2025 at 07:47:01PM +0000, Ricardo Ribalda wrote:
> Right now PM operations are always called at the same locations as
> uvc_status_(get|put).
>
> Combine them into uvc_status_(get|put). This simplifies the current
> code and future PM changes in the driver.
>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> drivers/media/usb/uvc/uvc_status.c | 38 +++++++++++++++++++++++++++++++++-----
> drivers/media/usb/uvc/uvc_v4l2.c | 11 +----------
> 2 files changed, 34 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
> index ee01dce4b783..caa673b0279d 100644
> --- a/drivers/media/usb/uvc/uvc_status.c
> +++ b/drivers/media/usb/uvc/uvc_status.c
> @@ -382,7 +382,7 @@ void uvc_status_suspend(struct uvc_device *dev)
> uvc_status_stop(dev);
> }
>
> -int uvc_status_get(struct uvc_device *dev)
> +static int _uvc_status_get(struct uvc_device *dev)
s/_uvc_status_get/__uvc_status_get/
> {
> int ret;
>
> @@ -399,13 +399,41 @@ int uvc_status_get(struct uvc_device *dev)
> return 0;
> }
>
> -void uvc_status_put(struct uvc_device *dev)
> +int uvc_status_get(struct uvc_device *dev)
> +{
> + int ret;
> +
> + ret = usb_autopm_get_interface(dev->intf);
> + if (ret)
> + return ret;
> +
> + ret = _uvc_status_get(dev);
> +
> + if (ret)
> + usb_autopm_put_interface(dev->intf);
> +
> + return ret;
> +}
> +
> +static int _uvc_status_put(struct uvc_device *dev)
s/_uvc_status_put/__uvc_status_put/
But unless you need to call this function in subsequent patches in the
series, I would merge it with uvc_status_put(). I think the same could
be done for get() too.
> {
> guard(mutex)(&dev->status_lock);
>
> if (dev->status_users == 1)
> uvc_status_stop(dev);
> - WARN_ON(!dev->status_users);
> - if (dev->status_users)
> - dev->status_users--;
> +
> + if (WARN_ON(!dev->status_users))
> + return -EIO;
That's a change in behaviour that should be at least explained in the
commit message.
> +
> + dev->status_users--;
> + return 0;
> +}
> +
> +void uvc_status_put(struct uvc_device *dev)
> +{
> + int ret;
> +
> + ret = _uvc_status_put(dev);
> + if (!ret)
> + usb_autopm_put_interface(dev->intf);
> }
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index 856eaa23e703..5d4e967938af 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -636,20 +636,13 @@ static int uvc_v4l2_open(struct file *file)
> stream = video_drvdata(file);
> uvc_dbg(stream->dev, CALLS, "%s\n", __func__);
>
> - ret = usb_autopm_get_interface(stream->dev->intf);
> - if (ret < 0)
> - return ret;
> -
> /* Create the device handle. */
> handle = kzalloc(sizeof(*handle), GFP_KERNEL);
> - if (handle == NULL) {
> - usb_autopm_put_interface(stream->dev->intf);
> + if (!handle)
> return -ENOMEM;
> - }
>
> ret = uvc_status_get(stream->dev);
> if (ret) {
> - usb_autopm_put_interface(stream->dev->intf);
> kfree(handle);
> return ret;
> }
> @@ -685,8 +678,6 @@ static int uvc_v4l2_release(struct file *file)
> file->private_data = NULL;
>
> uvc_status_put(stream->dev);
> -
> - usb_autopm_put_interface(stream->dev->intf);
This isn't right. The usb_autopm_get_interface() and
usb_autopm_put_interface() calls here are not mean to support UVC status
operation only. Sure, the patch doesn't introduce an issue as such, but
it bundles two things that are not related in a way that is confusing.
I expect that the code will improve in subsequent patches and the reason
will become clear, but at least the commit message here really needs to
explain why there's a temporary step backwards. Ideally the series
should be reorganized to avoid this.
> return 0;
> }
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2025-02-23 16:05 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
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 [this message]
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=20250223160534.GC27463@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®