V4L/DVB (10296): uvcvideo: Fix memory leak in input device handling
authorLaurent Pinchart <laurent.pinchart@skynet.be>
Thu, 22 Jan 2009 15:45:10 +0000 (12:45 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 30 Mar 2009 15:42:26 +0000 (12:42 -0300)
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.

Signed-off-by: Laurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/uvc/uvc_status.c
drivers/media/video/uvc/uvcvideo.h

index c705f248da8856d72c384d5b69b67df0c86a7567..21d87124986b57336afc53debe4315ce17d618a2 100644 (file)
 #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);
        input->dev.parent = &dev->intf->dev;
 
        __set_bit(EV_KEY, input->evbit);
@@ -57,7 +50,6 @@ static int uvc_input_init(struct uvc_device *dev)
 
 error:
        input_free_device(input);
-       kfree(phys);
        return ret;
 }
 
index b2639878f9b257232807a9d698ecd6a4c65d97eb..6f55c4d49cf408007c4730a4a416bc2341a50243 100644 (file)
@@ -647,6 +647,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;