mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Cai,Huoqing" <caihuoqing@baidu.com>
To: "Cai,Huoqing" <caihuoqing@baidu.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>
Subject: RE: [PATCH v3] usb: stkwebcam: Update the reference count of the usb device structure
Date: Thu, 2 Sep 2021 12:19:22 +0000	[thread overview]
Message-ID: <ddf5d61acbef4c60885cc5372c10a1df@baidu.com> (raw)
In-Reply-To: <20210901124650.31653-1-caihuoqing@baidu.com>

Hello,

+Cc Hans Verkuil <hverkuil@xs4all.nl>
Cai
> Subject: [PATCH v3] usb: stkwebcam: Update the reference count of the usb
> device structure
> 
> Use usb_get_dev() to increment the reference count of the usb device
> structure in order to avoid releasing the structure while it is still in
> use. And use usb_put_dev() to decrement the reference count and thus,
> when it will be equal to 0 the structure will be released.
> 
> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> ---
> v2->v3:
> *call usb_put_dev() in the error path of stk_camera_probe
> *move v4l2_ctrl_handler_free/v4l2_device_unregister/kfree(dev)
>  from stk_camera_disconnect() to stk_v4l_dev_release()
> 
> drivers/media/usb/stkwebcam/stk-webcam.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c
> b/drivers/media/usb/stkwebcam/stk-webcam.c
> index 0e231e576dc3..9f445e6ab5fa 100644
> --- a/drivers/media/usb/stkwebcam/stk-webcam.c
> +++ b/drivers/media/usb/stkwebcam/stk-webcam.c
> @@ -1234,6 +1234,11 @@ static void stk_v4l_dev_release(struct
> video_device *vd)
>  	if (dev->sio_bufs != NULL || dev->isobufs != NULL)
>  		pr_err("We are leaking memory\n");
>  	usb_put_intf(dev->interface);
> +	usb_put_dev(dev->udev);
> +
> +	v4l2_ctrl_handler_free(&dev->hdl);
> +	v4l2_device_unregister(&dev->v4l2_dev);
> +	kfree(dev);
>  }
> 
>  static const struct video_device stk_v4l_data = {
> @@ -1309,7 +1314,7 @@ static int stk_camera_probe(struct usb_interface
> *interface,
>  	init_waitqueue_head(&dev->wait_frame);
>  	dev->first_init = 1; /* webcam LED management */
> 
> -	dev->udev = udev;
> +	dev->udev = usb_get_dev(udev);
>  	dev->interface = interface;
>  	usb_get_intf(interface);
> 
> @@ -1365,6 +1370,7 @@ static int stk_camera_probe(struct usb_interface
> *interface,
> 
>  error_put:
>  	usb_put_intf(interface);
> +	usb_put_dev(dev->udev);
>  error:
>  	v4l2_ctrl_handler_free(hdl);
>  	v4l2_device_unregister(&dev->v4l2_dev);
> @@ -1385,9 +1391,6 @@ static void stk_camera_disconnect(struct
> usb_interface *interface)
>  		video_device_node_name(&dev->vdev));
> 
>  	video_unregister_device(&dev->vdev);
> -	v4l2_ctrl_handler_free(&dev->hdl);
> -	v4l2_device_unregister(&dev->v4l2_dev);
> -	kfree(dev);
>  }
> 
>  #ifdef CONFIG_PM
> --
> 2.25.1


      reply	other threads:[~2021-09-02 12:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 12:46 Cai Huoqing
2021-09-02 12:19 ` Cai,Huoqing [this message]

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=ddf5d61acbef4c60885cc5372c10a1df@baidu.com \
    --to=caihuoqing@baidu.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.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®