Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] usbvision-video: fix memory leak of alt_max_pkt_size

1. usbvision->alt_max_pkt_size is not deallocated anywhere.
2. if allocation of usbvision->alt_max_pkt_size fails,
there is no proper deallocation of already acquired resources.
The patch adds kfree(usbvision->alt_max_pkt_size) to
usbvision_release() as soon as other deallocations happen there.
It calls usbvision_release() if allocation of
usbvision->alt_max_pkt_size fails as soon as usbvision_release()
is safe to work with incompletely initialized usbvision structure.
Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Alexey Khoroshilov and committed by
Mauro Carvalho Chehab
090c65b6 b610b592

+2
+2
drivers/media/usb/usbvision/usbvision-video.c
··· 1460 1460 1461 1461 usbvision_remove_sysfs(usbvision->vdev); 1462 1462 usbvision_unregister_video(usbvision); 1463 + kfree(usbvision->alt_max_pkt_size); 1463 1464 1464 1465 usb_free_urb(usbvision->ctrl_urb); 1465 1466 ··· 1576 1575 usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL); 1577 1576 if (usbvision->alt_max_pkt_size == NULL) { 1578 1577 dev_err(&intf->dev, "usbvision: out of memory!\n"); 1578 + usbvision_release(usbvision); 1579 1579 return -ENOMEM; 1580 1580 } 1581 1581