V4L/DVB (9297): cx18: Fix memory leak on card initialization failure
[safe/jmp/linux-2.6] / drivers / media / video / stv680.c
index da94d3f..9c549d9 100644 (file)
@@ -84,7 +84,8 @@ static unsigned int debug;
 #define PDEBUG(level, fmt, args...) \
        do { \
        if (debug >= level)     \
-               info("[%s:%d] " fmt, __func__, __LINE__ , ## args);     \
+               printk(KERN_INFO KBUILD_MODNAME " [%s:%d] \n" fmt,      \
+                       __func__, __LINE__ , ## args);  \
        } while (0)
 
 
@@ -525,53 +526,54 @@ static int stv680_create_sysfs_files(struct video_device *vdev)
 {
        int rc;
 
-       rc = video_device_create_file(vdev, &dev_attr_model);
+       rc = device_create_file(&vdev->dev, &dev_attr_model);
        if (rc) goto err;
-       rc = video_device_create_file(vdev, &dev_attr_in_use);
+       rc = device_create_file(&vdev->dev, &dev_attr_in_use);
        if (rc) goto err_model;
-       rc = video_device_create_file(vdev, &dev_attr_streaming);
+       rc = device_create_file(&vdev->dev, &dev_attr_streaming);
        if (rc) goto err_inuse;
-       rc = video_device_create_file(vdev, &dev_attr_palette);
+       rc = device_create_file(&vdev->dev, &dev_attr_palette);
        if (rc) goto err_stream;
-       rc = video_device_create_file(vdev, &dev_attr_frames_total);
+       rc = device_create_file(&vdev->dev, &dev_attr_frames_total);
        if (rc) goto err_pal;
-       rc = video_device_create_file(vdev, &dev_attr_frames_read);
+       rc = device_create_file(&vdev->dev, &dev_attr_frames_read);
        if (rc) goto err_framtot;
-       rc = video_device_create_file(vdev, &dev_attr_packets_dropped);
+       rc = device_create_file(&vdev->dev, &dev_attr_packets_dropped);
        if (rc) goto err_framread;
-       rc = video_device_create_file(vdev, &dev_attr_decoding_errors);
+       rc = device_create_file(&vdev->dev, &dev_attr_decoding_errors);
        if (rc) goto err_dropped;
 
        return 0;
 
 err_dropped:
-       video_device_remove_file(vdev, &dev_attr_packets_dropped);
+       device_remove_file(&vdev->dev, &dev_attr_packets_dropped);
 err_framread:
-       video_device_remove_file(vdev, &dev_attr_frames_read);
+       device_remove_file(&vdev->dev, &dev_attr_frames_read);
 err_framtot:
-       video_device_remove_file(vdev, &dev_attr_frames_total);
+       device_remove_file(&vdev->dev, &dev_attr_frames_total);
 err_pal:
-       video_device_remove_file(vdev, &dev_attr_palette);
+       device_remove_file(&vdev->dev, &dev_attr_palette);
 err_stream:
-       video_device_remove_file(vdev, &dev_attr_streaming);
+       device_remove_file(&vdev->dev, &dev_attr_streaming);
 err_inuse:
-       video_device_remove_file(vdev, &dev_attr_in_use);
+       device_remove_file(&vdev->dev, &dev_attr_in_use);
 err_model:
-       video_device_remove_file(vdev, &dev_attr_model);
+       device_remove_file(&vdev->dev, &dev_attr_model);
 err:
+       PDEBUG(0, "STV(e): Could not create sysfs files");
        return rc;
 }
 
 static void stv680_remove_sysfs_files(struct video_device *vdev)
 {
-       video_device_remove_file(vdev, &dev_attr_model);
-       video_device_remove_file(vdev, &dev_attr_in_use);
-       video_device_remove_file(vdev, &dev_attr_streaming);
-       video_device_remove_file(vdev, &dev_attr_palette);
-       video_device_remove_file(vdev, &dev_attr_frames_total);
-       video_device_remove_file(vdev, &dev_attr_frames_read);
-       video_device_remove_file(vdev, &dev_attr_packets_dropped);
-       video_device_remove_file(vdev, &dev_attr_decoding_errors);
+       device_remove_file(&vdev->dev, &dev_attr_model);
+       device_remove_file(&vdev->dev, &dev_attr_in_use);
+       device_remove_file(&vdev->dev, &dev_attr_streaming);
+       device_remove_file(&vdev->dev, &dev_attr_palette);
+       device_remove_file(&vdev->dev, &dev_attr_frames_total);
+       device_remove_file(&vdev->dev, &dev_attr_frames_read);
+       device_remove_file(&vdev->dev, &dev_attr_packets_dropped);
+       device_remove_file(&vdev->dev, &dev_attr_decoding_errors);
 }
 
 /********************************************************************
@@ -1085,6 +1087,7 @@ static int stv_open (struct inode *inode, struct file *file)
        int err = 0;
 
        /* we are called with the BKL held */
+       lock_kernel();
        stv680->user = 1;
        err = stv_init (stv680);        /* main initialization routine for camera */
 
@@ -1098,6 +1101,7 @@ static int stv_open (struct inode *inode, struct file *file)
        }
        if (err)
                stv680->user = 0;
+       unlock_kernel();
 
        return err;
 }
@@ -1401,9 +1405,7 @@ static const struct file_operations stv680_fops = {
        .llseek =       no_llseek,
 };
 static struct video_device stv680_template = {
-       .owner =        THIS_MODULE,
        .name =         "STV0680 USB camera",
-       .type =         VID_TYPE_CAPTURE,
        .fops =         &stv680_fops,
        .release =      video_device_release,
        .minor =        -1,
@@ -1463,7 +1465,7 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
        mutex_init (&stv680->lock);
        wmb ();
 
-       if (video_register_device (stv680->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
+       if (video_register_device(stv680->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
                PDEBUG (0, "STV(e): video_register_device failed");
                retval = -EIO;
                goto error_vdev;
@@ -1551,7 +1553,8 @@ static int __init usb_stv680_init (void)
        }
        PDEBUG (0, "STV(i): usb camera driver version %s registering", DRIVER_VERSION);
 
-       info(DRIVER_DESC " " DRIVER_VERSION);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+              DRIVER_DESC "\n");
        return 0;
 }