drm: fix crash with fops lock and fixup sarea/page size locking
[deliverable/linux.git] / drivers / char / drm / drm_fops.c
index 403f44a1bf016cebe684f8d35719bf3b8d6dbf06..afe5f07f2e171e6001af950414d31df703080b07 100644 (file)
@@ -46,6 +46,7 @@ static int drm_setup(drm_device_t * dev)
        drm_local_map_t *map;
        int i;
        int ret;
+       u32 sareapage;
 
        if (dev->driver->firstopen) {
                ret = dev->driver->firstopen(dev);
@@ -53,8 +54,11 @@ static int drm_setup(drm_device_t * dev)
                        return ret;
        }
 
+       dev->magicfree.next = NULL;
+
        /* prebuild the SAREA */
-       i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM, _DRM_CONTAINS_LOCK, &map);
+       sareapage = max(SAREA_MAX, PAGE_SIZE);
+       i = drm_addmap(dev, 0, sareapage, _DRM_SHM, _DRM_CONTAINS_LOCK, &map);
        if (i != 0)
                return i;
 
@@ -69,13 +73,11 @@ static int drm_setup(drm_device_t * dev)
                        return i;
        }
 
-       for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++)
+       for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
                atomic_set(&dev->counts[i], 0);
 
-       for (i = 0; i < DRM_HASH_SIZE; i++) {
-               dev->magiclist[i].head = NULL;
-               dev->magiclist[i].tail = NULL;
-       }
+       drm_ht_create(&dev->magiclist, DRM_MAGIC_HASH_ORDER);
+       INIT_LIST_HEAD(&dev->magicfree);
 
        dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist), DRM_MEM_CTXLIST);
        if (dev->ctxlist == NULL)
@@ -84,7 +86,7 @@ static int drm_setup(drm_device_t * dev)
        INIT_LIST_HEAD(&dev->ctxlist->head);
 
        dev->vmalist = NULL;
-       dev->sigdata.lock = dev->lock.hw_lock = NULL;
+       dev->sigdata.lock = NULL;
        init_waitqueue_head(&dev->lock.lock_queue);
        dev->queue_count = 0;
        dev->queue_reserved = 0;
@@ -175,7 +177,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
        drm_device_t *dev = NULL;
        int minor = iminor(inode);
        int err = -ENODEV;
-       struct file_operations *old_fops;
+       const struct file_operations *old_fops;
 
        DRM_DEBUG("\n");
 
@@ -262,7 +264,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
                        goto out_free;
        }
 
-       down(&dev->struct_sem);
+       mutex_lock(&dev->struct_mutex);
        if (!dev->file_last) {
                priv->next = NULL;
                priv->prev = NULL;
@@ -276,7 +278,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
                dev->file_last->next = priv;
                dev->file_last = priv;
        }
-       up(&dev->struct_sem);
+       mutex_unlock(&dev->struct_mutex);
 
 #ifdef __alpha__
        /*
@@ -413,7 +415,7 @@ int drm_release(struct inode *inode, struct file *filp)
 
        drm_fasync(-1, filp, 0);
 
-       down(&dev->ctxlist_sem);
+       mutex_lock(&dev->ctxlist_mutex);
        if (dev->ctxlist && (!list_empty(&dev->ctxlist->head))) {
                drm_ctx_list_t *pos, *n;
 
@@ -432,9 +434,9 @@ int drm_release(struct inode *inode, struct file *filp)
                        }
                }
        }
-       up(&dev->ctxlist_sem);
+       mutex_unlock(&dev->ctxlist_mutex);
 
-       down(&dev->struct_sem);
+       mutex_lock(&dev->struct_mutex);
        if (priv->remove_auth_on_close == 1) {
                drm_file_t *temp = dev->file_first;
                while (temp) {
@@ -452,7 +454,7 @@ int drm_release(struct inode *inode, struct file *filp)
        } else {
                dev->file_last = priv->prev;
        }
-       up(&dev->struct_sem);
+       mutex_unlock(&dev->struct_mutex);
 
        if (dev->driver->postclose)
                dev->driver->postclose(dev, priv);
This page took 0.026822 seconds and 5 git commands to generate.