提交 e7f7ab45 编写于 作者: D Dave Airlie 提交者: Dave Airlie

drm: cleanup exit path for module unload

The current sub-module unload exit path is a mess, it tries
to abuse the idr. Just keep a list of devices per driver struct
and free them in-order on rmmod.
Signed-off-by: NDave Airlie <airlied@redhat.com>
上级 4a6908a3
...@@ -263,6 +263,8 @@ int drm_init(struct drm_driver *driver) ...@@ -263,6 +263,8 @@ int drm_init(struct drm_driver *driver)
DRM_DEBUG("\n"); DRM_DEBUG("\n");
INIT_LIST_HEAD(&driver->device_list);
for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) { for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
pid = (struct pci_device_id *)&driver->pci_driver.id_table[i]; pid = (struct pci_device_id *)&driver->pci_driver.id_table[i];
...@@ -334,30 +336,13 @@ static void drm_cleanup(struct drm_device * dev) ...@@ -334,30 +336,13 @@ static void drm_cleanup(struct drm_device * dev)
DRM_ERROR("Cannot unload module\n"); DRM_ERROR("Cannot unload module\n");
} }
static int drm_minors_cleanup(int id, void *ptr, void *data)
{
struct drm_minor *minor = ptr;
struct drm_device *dev;
struct drm_driver *driver = data;
dev = minor->dev;
if (minor->dev->driver != driver)
return 0;
if (minor->type != DRM_MINOR_LEGACY)
return 0;
if (dev)
pci_dev_put(dev->pdev);
drm_cleanup(dev);
return 1;
}
void drm_exit(struct drm_driver *driver) void drm_exit(struct drm_driver *driver)
{ {
struct drm_device *dev, *tmp;
DRM_DEBUG("\n"); DRM_DEBUG("\n");
idr_for_each(&drm_minors_idr, &drm_minors_cleanup, driver); list_for_each_entry_safe(dev, tmp, &driver->device_list, driver_item)
drm_cleanup(dev);
DRM_INFO("Module unloaded\n"); DRM_INFO("Module unloaded\n");
} }
......
...@@ -270,6 +270,8 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent, ...@@ -270,6 +270,8 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY))) if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY)))
goto err_g2; goto err_g2;
list_add_tail(&dev->driver_item, &driver->device_list);
DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
driver->name, driver->major, driver->minor, driver->patchlevel, driver->name, driver->major, driver->minor, driver->patchlevel,
driver->date, dev->primary->index); driver->date, dev->primary->index);
......
...@@ -737,6 +737,8 @@ struct drm_driver { ...@@ -737,6 +737,8 @@ struct drm_driver {
int num_ioctls; int num_ioctls;
struct file_operations fops; struct file_operations fops;
struct pci_driver pci_driver; struct pci_driver pci_driver;
/* List of devices hanging off this driver */
struct list_head device_list;
}; };
#define DRM_MINOR_UNASSIGNED 0 #define DRM_MINOR_UNASSIGNED 0
...@@ -759,6 +761,7 @@ struct drm_minor { ...@@ -759,6 +761,7 @@ struct drm_minor {
* may contain multiple heads. * may contain multiple heads.
*/ */
struct drm_device { struct drm_device {
struct list_head driver_item; /**< list of devices per driver */
char *unique; /**< Unique identifier: e.g., busid */ char *unique; /**< Unique identifier: e.g., busid */
int unique_len; /**< Length of unique field */ int unique_len; /**< Length of unique field */
char *devname; /**< For /proc/interrupts */ char *devname; /**< For /proc/interrupts */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册