aboutsummaryrefslogtreecommitdiff
path: root/linux-core/drm_fops.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2008-08-04 14:54:32 +1000
committerDave Airlie <airlied@redhat.com>2008-08-04 14:54:32 +1000
commit717dd804d0d1d9984345a998b28ee47079c70639 (patch)
treed1c0f9c6f267ef42215ed42c23d8c0afc0948e17 /linux-core/drm_fops.c
parentaf6efc3d778b96164849f822331938c4cdf8f4b2 (diff)
drm: fixup master code to use krefs
Diffstat (limited to 'linux-core/drm_fops.c')
-rw-r--r--linux-core/drm_fops.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/linux-core/drm_fops.c b/linux-core/drm_fops.c
index 8eb20b47..f45d5e46 100644
--- a/linux-core/drm_fops.c
+++ b/linux-core/drm_fops.c
@@ -260,28 +260,34 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
/* if there is no current master make this fd it */
mutex_lock(&dev->struct_mutex);
if (!priv->minor->master) {
- priv->minor->master = drm_get_master(priv->minor);
+ /* create a new master */
+ priv->minor->master = drm_master_create(priv->minor);
if (!priv->minor->master) {
ret = -ENOMEM;
goto out_free;
}
priv->is_master = 1;
- priv->master = priv->minor->master;
+ /* take another reference for the copy in the local file priv */
+ priv->master = drm_master_get(priv->minor->master);
priv->authenticated = 1;
+
mutex_unlock(&dev->struct_mutex);
if (dev->driver->master_create) {
ret = dev->driver->master_create(dev, priv->master);
if (ret) {
- drm_put_master(priv->minor->master);
- priv->minor->master = priv->master = NULL;
+ mutex_lock(&dev->struct_mutex);
+ /* drop both references if this fails */
+ drm_master_put(&priv->minor->master);
+ drm_master_put(&priv->master);
mutex_unlock(&dev->struct_mutex);
goto out_free;
}
}
} else {
- priv->master = priv->minor->master;
+ /* get a reference to the master */
+ priv->master = drm_master_get(priv->minor->master);
mutex_unlock(&dev->struct_mutex);
}
@@ -453,6 +459,8 @@ int drm_release(struct inode *inode, struct file *filp)
if (drm_core_check_feature(dev, DRIVER_MODESET))
drm_fb_release(filp);
+ mutex_lock(&dev->struct_mutex);
+
if (file_priv->is_master) {
struct drm_file *temp;
list_for_each_entry(temp, &dev->filelist, lhead) {
@@ -461,18 +469,17 @@ int drm_release(struct inode *inode, struct file *filp)
temp->authenticated = 0;
}
- if (file_priv->minor->master == file_priv->master)
- file_priv->minor->master = NULL;
- drm_put_master(file_priv->master);
+ if (file_priv->minor->master == file_priv->master) {
+ /* drop the reference held my the minor */
+ drm_master_put(&file_priv->minor->master);
+ }
}
- file_priv->master = NULL;
+ /* drop the reference held my the file priv */
+ drm_master_put(&file_priv->master);
file_priv->is_master = 0;
- mutex_lock(&dev->struct_mutex);
-
list_del(&file_priv->lhead);
-
mutex_unlock(&dev->struct_mutex);
if (dev->driver->postclose)