From: Dave Airlie Date: Wed, 14 Jul 2004 12:34:55 +0000 (+0000) Subject: Fix reference counting for stub for new Linux PCI probe X-Git-Tag: submit/1.0/20121108.012404~2073 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb5112b616080033ab9f09092098527f2aa09b70;p=profile%2Fivi%2Flibdrm.git Fix reference counting for stub for new Linux PCI probe --- diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c index 1a01db5..c4d4391 100644 --- a/linux-core/drm_drv.c +++ b/linux-core/drm_drv.c @@ -152,6 +152,7 @@ struct drm_stub_info { drm_device_t *dev); int (*info_unregister)(int minor); struct class_simple *drm_class; + int *info_count; }; extern struct drm_stub_info DRM(stub_info); @@ -778,6 +779,7 @@ static void __exit drm_cleanup( drm_device_t *dev ) static void __exit drm_exit (void) { + DRM_DEBUG( "\n" ); if (DRM(fb_loaded)==1) { int i; diff --git a/linux-core/drm_stub.c b/linux-core/drm_stub.c index 96fd727..1426af0 100644 --- a/linux-core/drm_stub.c +++ b/linux-core/drm_stub.c @@ -111,6 +111,7 @@ static int DRM(stub_getminor)(const char *name, struct file_operations *fops, DRM(stub_root) = DRM(proc_init)(dev, i, DRM(stub_root), &DRM(stub_list)[i] .dev_root); + *DRM(stub_info).info_count++; return i; } } @@ -134,7 +135,10 @@ static int DRM(stub_putminor)(int minor) DRM(stub_list)[minor].fops = NULL; DRM(proc_cleanup)(minor, DRM(stub_root), DRM(stub_list)[minor].dev_root); - if (minor) { + + *DRM(stub_info).info_count--; + + if ((*DRM(stub_info).info_count)!=0) { inter_module_put("drm"); } else { inter_module_unregister("drm"); @@ -180,8 +184,9 @@ int DRM(stub_register)(const char *name, struct file_operations *fops, DRM(stub_info).info_register = i->info_register; DRM(stub_info).info_unregister = i->info_unregister; DRM(stub_info).drm_class = i->drm_class; + DRM(stub_info).info_count = i->info_count; DRM_DEBUG("already registered\n"); - } else if (DRM(stub_info).drm_class == NULL) { + } else if (*DRM(stub_info).info_count == 0) { DRM(stub_info).drm_class = class_simple_create(THIS_MODULE, "drm"); if (IS_ERR(DRM(stub_info).drm_class)) { printk (KERN_ERR "Error creating drm class.\n"); @@ -221,9 +226,12 @@ int DRM(stub_unregister)(int minor) return -1; } +int DRM(stub_count); + /** Stub information */ struct drm_stub_info DRM(stub_info) = { .info_register = DRM(stub_getminor), .info_unregister = DRM(stub_putminor), .drm_class = NULL, + .info_count = &DRM(stub_count), }; diff --git a/linux/drm_drv.h b/linux/drm_drv.h index 1a01db5..c4d4391 100644 --- a/linux/drm_drv.h +++ b/linux/drm_drv.h @@ -152,6 +152,7 @@ struct drm_stub_info { drm_device_t *dev); int (*info_unregister)(int minor); struct class_simple *drm_class; + int *info_count; }; extern struct drm_stub_info DRM(stub_info); @@ -778,6 +779,7 @@ static void __exit drm_cleanup( drm_device_t *dev ) static void __exit drm_exit (void) { + DRM_DEBUG( "\n" ); if (DRM(fb_loaded)==1) { int i; diff --git a/linux/drm_stub.h b/linux/drm_stub.h index 96fd727..1426af0 100644 --- a/linux/drm_stub.h +++ b/linux/drm_stub.h @@ -111,6 +111,7 @@ static int DRM(stub_getminor)(const char *name, struct file_operations *fops, DRM(stub_root) = DRM(proc_init)(dev, i, DRM(stub_root), &DRM(stub_list)[i] .dev_root); + *DRM(stub_info).info_count++; return i; } } @@ -134,7 +135,10 @@ static int DRM(stub_putminor)(int minor) DRM(stub_list)[minor].fops = NULL; DRM(proc_cleanup)(minor, DRM(stub_root), DRM(stub_list)[minor].dev_root); - if (minor) { + + *DRM(stub_info).info_count--; + + if ((*DRM(stub_info).info_count)!=0) { inter_module_put("drm"); } else { inter_module_unregister("drm"); @@ -180,8 +184,9 @@ int DRM(stub_register)(const char *name, struct file_operations *fops, DRM(stub_info).info_register = i->info_register; DRM(stub_info).info_unregister = i->info_unregister; DRM(stub_info).drm_class = i->drm_class; + DRM(stub_info).info_count = i->info_count; DRM_DEBUG("already registered\n"); - } else if (DRM(stub_info).drm_class == NULL) { + } else if (*DRM(stub_info).info_count == 0) { DRM(stub_info).drm_class = class_simple_create(THIS_MODULE, "drm"); if (IS_ERR(DRM(stub_info).drm_class)) { printk (KERN_ERR "Error creating drm class.\n"); @@ -221,9 +226,12 @@ int DRM(stub_unregister)(int minor) return -1; } +int DRM(stub_count); + /** Stub information */ struct drm_stub_info DRM(stub_info) = { .info_register = DRM(stub_getminor), .info_unregister = DRM(stub_putminor), .drm_class = NULL, + .info_count = &DRM(stub_count), };