Re: [kbuild] Re: [PATCH v2 5/5] media: uvcvideo: Abort uvc_v4l2_open if video device is unregistered

2020-09-09 Thread Guenter Roeck
On 9/9/20 5:19 AM, Dan Carpenter wrote:
> Hi Guenter,
> 
> url:
> https://github.com/0day-ci/linux/commits/Guenter-Roeck/media-uvcvideo-Fix-race-conditions/20200909-121927
>  
> base:   git://linuxtv.org/media_tree.git master
> config: x86_64-randconfig-m001-20200909 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot 
> Reported-by: Dan Carpenter 
> 
> smatch warnings:
> drivers/media/usb/uvc/uvc_v4l2.c:553 uvc_v4l2_open() warn: possible memory 
> leak of 'handle'
> 

Good catch. It is also missing a call to usb_autopm_put_interface().
I'll fix that in v3.

Thanks,
Guenter

> # 
> https://github.com/0day-ci/linux/commit/50911975ff9b21d08ff5408e496683b8ac567b1c
>  
> git remote add linux-review https://github.com/0day-ci/linux 
> git fetch --no-tags linux-review 
> Guenter-Roeck/media-uvcvideo-Fix-race-conditions/20200909-121927
> git checkout 50911975ff9b21d08ff5408e496683b8ac567b1c
> vim +/handle +553 drivers/media/usb/uvc/uvc_v4l2.c
> 
> bec43661b1dc00 drivers/media/video/uvc/uvc_v4l2.c Hans Verkuil 2008-12-30 
>  530  static int uvc_v4l2_open(struct file *file)
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  531  {
> 35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28 
>  532struct uvc_streaming *stream;
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  533struct uvc_fh *handle;
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  534int ret = 0;
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  535  
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  536uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
> 35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28 
>  537stream = video_drvdata(file);
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  538  
> 35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28 
>  539ret = usb_autopm_get_interface(stream->dev->intf);
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  540if (ret < 0)
> 716fdee110ceb8 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-09-29 
>  541return ret;
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  542  
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  543/* Create the device handle. */
> f14d4988c28e52 drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2018-01-16 
>  544handle = kzalloc(sizeof(*handle), GFP_KERNEL);
>   
>   
> 
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  545if (handle == NULL) {
> 35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28 
>  546usb_autopm_put_interface(stream->dev->intf);
> 716fdee110ceb8 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-09-29 
>  547return -ENOMEM;
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  548}
> c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30 
>  549  
> 17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25 
>  550mutex_lock(>dev->lock);
> 50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08 
>  551if (!video_is_registered(>vdev)) {
> 50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08 
>  552mutex_unlock(>dev->lock);
> 50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08 
> @553return -ENODEV;
>   
>   ^^
> kfree(handle);
> 
> 50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08 
>  554}
> 17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25 
>  555if (stream->dev->users == 0) {
> 17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25 
>  556ret = uvc_status_start(stream->dev, GFP_KERNEL);
> 35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28 
>  557if (ret < 0) {
> 17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25 
>  558mutex_unlock(>dev->lock);
> a82a45f65377b0 drivers/media/usb/uvc/uvc_v4l2.c   Oliver Neukum2013-01-10 
>  559usb_autopm_put_interface(stream->dev->intf);
> 04a37e0f32f988 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-05-19 
>  560kfree(handle);
> 716fdee110ceb8 

[kbuild] Re: [PATCH v2 5/5] media: uvcvideo: Abort uvc_v4l2_open if video device is unregistered

2020-09-09 Thread Dan Carpenter
Hi Guenter,

url:
https://github.com/0day-ci/linux/commits/Guenter-Roeck/media-uvcvideo-Fix-race-conditions/20200909-121927
 
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-m001-20200909 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 
Reported-by: Dan Carpenter 

smatch warnings:
drivers/media/usb/uvc/uvc_v4l2.c:553 uvc_v4l2_open() warn: possible memory leak 
of 'handle'

# 
https://github.com/0day-ci/linux/commit/50911975ff9b21d08ff5408e496683b8ac567b1c
 
git remote add linux-review https://github.com/0day-ci/linux 
git fetch --no-tags linux-review 
Guenter-Roeck/media-uvcvideo-Fix-race-conditions/20200909-121927
git checkout 50911975ff9b21d08ff5408e496683b8ac567b1c
vim +/handle +553 drivers/media/usb/uvc/uvc_v4l2.c

bec43661b1dc00 drivers/media/video/uvc/uvc_v4l2.c Hans Verkuil 2008-12-30  
530  static int uvc_v4l2_open(struct file *file)
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
531  {
35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28  
532  struct uvc_streaming *stream;
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
533  struct uvc_fh *handle;
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
534  int ret = 0;
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
535  
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
536  uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28  
537  stream = video_drvdata(file);
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
538  
35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28  
539  ret = usb_autopm_get_interface(stream->dev->intf);
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
540  if (ret < 0)
716fdee110ceb8 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-09-29  
541  return ret;
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
542  
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
543  /* Create the device handle. */
f14d4988c28e52 drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2018-01-16  
544  handle = kzalloc(sizeof(*handle), GFP_KERNEL);



c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
545  if (handle == NULL) {
35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28  
546  usb_autopm_put_interface(stream->dev->intf);
716fdee110ceb8 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-09-29  
547  return -ENOMEM;
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
548  }
c0efd232929c2c drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2008-06-30  
549  
17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25  
550  mutex_lock(>dev->lock);
50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08  
551  if (!video_is_registered(>vdev)) {
50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08  
552  mutex_unlock(>dev->lock);
50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08 
@553  return -ENODEV;

^^
kfree(handle);

50911975ff9b21 drivers/media/usb/uvc/uvc_v4l2.c   Guenter Roeck2020-09-08  
554  }
17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25  
555  if (stream->dev->users == 0) {
17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25  
556  ret = uvc_status_start(stream->dev, GFP_KERNEL);
35f02a681b72ec drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-06-28  
557  if (ret < 0) {
17706f5653a90f drivers/media/usb/uvc/uvc_v4l2.c   Laurent Pinchart 2013-04-25  
558  mutex_unlock(>dev->lock);
a82a45f65377b0 drivers/media/usb/uvc/uvc_v4l2.c   Oliver Neukum2013-01-10  
559  usb_autopm_put_interface(stream->dev->intf);
04a37e0f32f988 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-05-19  
560  kfree(handle);
716fdee110ceb8 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-09-29  
561  return ret;
04a37e0f32f988 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-05-19  
562  }
04a37e0f32f988 drivers/media/video/uvc/uvc_v4l2.c Laurent Pinchart 2009-05-19  
563  }
04a37e0f32f988