From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Kieran Bingham <kieran.bingham@ideasonboard.com>
Cc: linux-media@vger.kernel.org,
Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
Olivier BRAUN <olivier.braun@stereolabs.com>,
Troy Kisky <troy.kisky@boundarydevices.com>,
Randy Dunlap <rdunlap@infradead.org>,
Philipp Zabel <philipp.zabel@gmail.com>,
Ezequiel Garcia <ezequiel@collabora.com>,
Tomasz Figa <tfiga@google.com>,
Keiichi Watanabe <keiichiw@chromium.org>
Subject: Re: [PATCH v6 06/10] media: uvcvideo: Abstract streaming object lifetime
Date: Tue, 04 Dec 2018 14:51:41 +0200 [thread overview]
Message-ID: <3745852.l7B5QHa1Fj@avalon> (raw)
In-Reply-To: <207851fbe7c980dee983f5c3587f911457e37f34.1541782862.git-series.kieran.bingham@ideasonboard.com>
Hi Kieran,
Thank you for the patch.
On Friday, 9 November 2018 19:05:29 EET Kieran Bingham wrote:
> The streaming object is a key part of handling the UVC device. Although
> not critical, we are currently missing a call to destroy the mutex on
> clean up paths, and we are due to extend the objects complexity in the
> near future.
>
> Facilitate easy management of a stream object by creating a pair of
> functions to handle creating and destroying the allocation. The new
> uvc_stream_delete() function also performs the missing mutex_destroy()
> operation.
>
> Previously a failed streaming object allocation would cause
> uvc_parse_streaming() to return -EINVAL, which is inappropriate. If the
> constructor failes, we will instead return -ENOMEM.
>
> While we're here, fix the trivial spelling error in the function banner
> of uvc_delete().
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> drivers/media/usb/uvc/uvc_driver.c | 54 +++++++++++++++++++++----------
> 1 file changed, 38 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_driver.c
> b/drivers/media/usb/uvc/uvc_driver.c index 67bd58c6f397..afb44d1c9d04
> 100644
> --- a/drivers/media/usb/uvc/uvc_driver.c
> +++ b/drivers/media/usb/uvc/uvc_driver.c
> @@ -396,6 +396,39 @@ static struct uvc_streaming *uvc_stream_by_id(struct
> uvc_device *dev, int id) }
>
> /* ------------------------------------------------------------------------
> + * Streaming Object Management
> + */
> +
> +static void uvc_stream_delete(struct uvc_streaming *stream)
> +{
> + mutex_destroy(&stream->mutex);
> +
> + usb_put_intf(stream->intf);
> +
> + kfree(stream->format);
> + kfree(stream->header.bmaControls);
> + kfree(stream);
> +}
> +
> +static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev,
> + struct usb_interface *intf)
> +{
> + struct uvc_streaming *stream;
> +
> + stream = kzalloc(sizeof(*stream), GFP_KERNEL);
> + if (stream == NULL)
> + return NULL;
> +
> + mutex_init(&stream->mutex);
> +
> + stream->dev = dev;
> + stream->intf = usb_get_intf(intf);
> + stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
> +
> + return stream;
> +}
> +
> +/* ------------------------------------------------------------------------
> * Descriptors parsing
> */
>
> @@ -687,17 +720,12 @@ static int uvc_parse_streaming(struct uvc_device *dev,
> return -EINVAL;
> }
>
> - streaming = kzalloc(sizeof(*streaming), GFP_KERNEL);
> + streaming = uvc_stream_new(dev, intf);
> if (streaming == NULL) {
> usb_driver_release_interface(&uvc_driver.driver, intf);
> - return -EINVAL;
> + return -ENOMEM;
> }
>
> - mutex_init(&streaming->mutex);
> - streaming->dev = dev;
> - streaming->intf = usb_get_intf(intf);
> - streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
> -
> /* The Pico iMage webcam has its class-specific interface descriptors
> * after the endpoint descriptors.
> */
> @@ -904,10 +932,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
>
> error:
> usb_driver_release_interface(&uvc_driver.driver, intf);
> - usb_put_intf(intf);
> - kfree(streaming->format);
> - kfree(streaming->header.bmaControls);
> - kfree(streaming);
> + uvc_stream_delete(streaming);
> return ret;
> }
>
> @@ -1815,7 +1840,7 @@ static int uvc_scan_device(struct uvc_device *dev)
> * is released.
> *
> * As this function is called after or during disconnect(), all URBs have
> - * already been canceled by the USB core. There is no need to kill the
> + * already been cancelled by the USB core. There is no need to kill the
> * interrupt URB manually.
> */
> static void uvc_delete(struct kref *kref)
> @@ -1853,10 +1878,7 @@ static void uvc_delete(struct kref *kref)
> streaming = list_entry(p, struct uvc_streaming, list);
> usb_driver_release_interface(&uvc_driver.driver,
> streaming->intf);
> - usb_put_intf(streaming->intf);
> - kfree(streaming->format);
> - kfree(streaming->header.bmaControls);
> - kfree(streaming);
> + uvc_stream_delete(streaming);
> }
>
> kfree(dev);
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2018-12-04 12:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-09 17:05 [PATCH v6 00/10] Asynchronous UVC Kieran Bingham
2018-11-09 17:05 ` [PATCH v6 01/10] media: uvcvideo: Refactor URB descriptors Kieran Bingham
2018-11-09 17:05 ` [PATCH v6 02/10] media: uvcvideo: Convert decode functions to use new context structure Kieran Bingham
2018-11-09 17:05 ` [PATCH v6 03/10] media: uvcvideo: Protect queue internals with helper Kieran Bingham
2018-11-09 17:05 ` [PATCH v6 04/10] media: uvcvideo: queue: Simplify spin-lock usage Kieran Bingham
2018-11-09 17:05 ` [PATCH v6 05/10] media: uvcvideo: queue: Support asynchronous buffer handling Kieran Bingham
2018-11-10 16:30 ` Laurent Pinchart
2018-11-09 17:05 ` [PATCH v6 06/10] media: uvcvideo: Abstract streaming object lifetime Kieran Bingham
2018-12-04 12:51 ` Laurent Pinchart [this message]
2018-11-09 17:05 ` [PATCH v6 07/10] media: uvcvideo: Move decode processing to process context Kieran Bingham
2018-12-04 12:55 ` Laurent Pinchart
2018-11-09 17:05 ` [PATCH v6 08/10] media: uvcvideo: Split uvc_video_enable into two Kieran Bingham
2018-11-10 22:02 ` Kieran Bingham
2018-12-04 12:59 ` Laurent Pinchart
2018-11-09 17:05 ` [PATCH v6 09/10] media: uvcvideo: Rename uvc_{un,}init_video() Kieran Bingham
2018-11-09 17:15 ` Kieran Bingham
2018-12-04 13:05 ` Laurent Pinchart
2018-11-09 17:05 ` [PATCH v6 10/10] media: uvcvideo: Utilise for_each_uvc_urb iterator Kieran Bingham
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=3745852.l7B5QHa1Fj@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=ezequiel@collabora.com \
--cc=g.liakhovetski@gmx.de \
--cc=keiichiw@chromium.org \
--cc=kieran.bingham@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=olivier.braun@stereolabs.com \
--cc=philipp.zabel@gmail.com \
--cc=rdunlap@infradead.org \
--cc=tfiga@google.com \
--cc=troy.kisky@boundarydevices.com \
/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.