From 8031abacbe51fa4062ff4bf1a34751b6a39460eb Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 22 Jan 2009 16:45:10 +0100 Subject: uvcvideo: Fix memory leak in input device handling From: Laurent Pinchart The dynamically allocated input_dev->phys buffer isn't freed when unregistering the device. As the input layer doesn't provide any release callback, use a fixed-size buffer inside the uvc_device structure. Priority: normal Signed-off-by: Laurent Pinchart --- linux/drivers/media/video/uvc/uvc_status.c | 16 ++++------------ linux/drivers/media/video/uvc/uvcvideo.h | 1 + 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/linux/drivers/media/video/uvc/uvc_status.c b/linux/drivers/media/video/uvc/uvc_status.c index 77a263463..4f4171fa8 100644 --- a/linux/drivers/media/video/uvc/uvc_status.c +++ b/linux/drivers/media/video/uvc/uvc_status.c @@ -28,26 +28,19 @@ #ifdef CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV static int uvc_input_init(struct uvc_device *dev) { - struct usb_device *udev = dev->udev; struct input_dev *input; - char *phys = NULL; int ret; input = input_allocate_device(); if (input == NULL) return -ENOMEM; - phys = kmalloc(6 + strlen(udev->bus->bus_name) + strlen(udev->devpath), - GFP_KERNEL); - if (phys == NULL) { - ret = -ENOMEM; - goto error; - } - sprintf(phys, "usb-%s-%s", udev->bus->bus_name, udev->devpath); + usb_make_path(dev->udev, dev->input_phys, sizeof(dev->input_phys)); + strlcat(dev->input_phys, "/button", sizeof(dev->input_phys)); input->name = dev->name; - input->phys = phys; - usb_to_input_id(udev, &input->id); + input->phys = dev->input_phys; + usb_to_input_id(dev->udev, &input->id); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) input->dev.parent = &dev->intf->dev; #else @@ -65,7 +58,6 @@ static int uvc_input_init(struct uvc_device *dev) error: input_free_device(input); - kfree(phys); return ret; } diff --git a/linux/drivers/media/video/uvc/uvcvideo.h b/linux/drivers/media/video/uvc/uvcvideo.h index f0eef72b9..408b8b846 100644 --- a/linux/drivers/media/video/uvc/uvcvideo.h +++ b/linux/drivers/media/video/uvc/uvcvideo.h @@ -648,6 +648,7 @@ struct uvc_device { struct urb *int_urb; __u8 *status; struct input_dev *input; + char input_phys[64]; /* Video Streaming interfaces */ struct list_head streaming; -- cgit v1.2.3