V4L/DVB: pvrusb2: Fix USB parent device reference count
authorMike Isely <isely@pobox.com>
Sat, 15 May 2010 03:23:46 +0000 (00:23 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 1 Jun 2010 04:19:54 +0000 (01:19 -0300)
pvrusb2: Correctly reference count pointer to parent USB device when linked
from sysfs interface.  This is technically a pretty nasty problem,
however as far as I know nobody had been getting burned by it (yet).

Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/pvrusb2/pvrusb2-sysfs.c

index 71f5056..bf47851 100644 (file)
@@ -511,6 +511,7 @@ static void pvr2_sysfs_release(struct device *class_dev)
 
 static void class_dev_destroy(struct pvr2_sysfs *sfp)
 {
+       struct device *dev;
        if (!sfp->class_dev) return;
 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
        pvr2_sysfs_tear_down_debugifc(sfp);
@@ -542,6 +543,9 @@ static void class_dev_destroy(struct pvr2_sysfs *sfp)
        }
        pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
        dev_set_drvdata(sfp->class_dev, NULL);
+       dev = sfp->class_dev->parent;
+       sfp->class_dev->parent = NULL;
+       put_device(dev);
        device_unregister(sfp->class_dev);
        sfp->class_dev = NULL;
 }
@@ -631,10 +635,11 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
        pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
 
        class_dev->class = &class_ptr->class;
+
        dev_set_name(class_dev, "%s",
                     pvr2_hdw_get_device_identifier(sfp->channel.hdw));
 
-       class_dev->parent = &usb_dev->dev;
+       class_dev->parent = get_device(&usb_dev->dev);
 
        sfp->class_dev = class_dev;
        dev_set_drvdata(class_dev, sfp);
@@ -775,7 +780,8 @@ struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
        struct pvr2_sysfs_class *clp;
        clp = kzalloc(sizeof(*clp),GFP_KERNEL);
        if (!clp) return clp;
-       pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
+       pvr2_sysfs_trace("Creating and registering pvr2_sysfs_class id=%p",
+                        clp);
        clp->class.name = "pvrusb2";
        clp->class.class_release = pvr2_sysfs_class_release;
        clp->class.dev_release = pvr2_sysfs_release;
@@ -791,6 +797,7 @@ struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
 
 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
 {
+       pvr2_sysfs_trace("Unregistering pvr2_sysfs_class id=%p", clp);
        class_unregister(&clp->class);
 }