drm: Refactor drop/set master code a bit
File open/set_maseter ioctl and file close/drop_master ioctl share the same master handling code. Extract it. Note that vmwgfx's master_set callback needs to know whether the master is a new one or has been used already, so thread this through. On the close/drop side a similar parameter existed, but wasnt used. Drop it to simplify the flow. v2: Try to make it not leak so much (Emil). v3: Send out the right version ... Cc: Emil Velikov <emil.l.velikov@gmail.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/1466511638-9885-1-git-send-email-daniel.vetter@ffwll.ch
This commit is contained in:
parent
a325725633
commit
d6ed682eba
|
@ -110,6 +110,24 @@ static struct drm_master *drm_master_create(struct drm_device *dev)
|
||||||
return master;
|
return master;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int drm_set_master(struct drm_device *dev, struct drm_file *fpriv,
|
||||||
|
bool new_master)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
dev->master = drm_master_get(fpriv->master);
|
||||||
|
fpriv->is_master = 1;
|
||||||
|
if (dev->driver->master_set) {
|
||||||
|
ret = dev->driver->master_set(dev, fpriv, new_master);
|
||||||
|
if (unlikely(ret != 0)) {
|
||||||
|
fpriv->is_master = 0;
|
||||||
|
drm_master_put(&dev->master);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* drm_new_set_master - Allocate a new master object and become master for the
|
* drm_new_set_master - Allocate a new master object and become master for the
|
||||||
* associated master realm.
|
* associated master realm.
|
||||||
|
@ -127,37 +145,32 @@ static int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv)
|
||||||
|
|
||||||
lockdep_assert_held_once(&dev->master_mutex);
|
lockdep_assert_held_once(&dev->master_mutex);
|
||||||
|
|
||||||
/* create a new master */
|
|
||||||
dev->master = drm_master_create(dev);
|
|
||||||
if (!dev->master)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
/* take another reference for the copy in the local file priv */
|
|
||||||
old_master = fpriv->master;
|
old_master = fpriv->master;
|
||||||
fpriv->master = drm_master_get(dev->master);
|
fpriv->master = drm_master_create(dev);
|
||||||
|
if (!fpriv->master) {
|
||||||
|
fpriv->master = old_master;
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
if (dev->driver->master_create) {
|
if (dev->driver->master_create) {
|
||||||
ret = dev->driver->master_create(dev, fpriv->master);
|
ret = dev->driver->master_create(dev, fpriv->master);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
}
|
}
|
||||||
if (dev->driver->master_set) {
|
|
||||||
ret = dev->driver->master_set(dev, fpriv, true);
|
|
||||||
if (ret)
|
|
||||||
goto out_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
fpriv->is_master = 1;
|
|
||||||
fpriv->allowed_master = 1;
|
fpriv->allowed_master = 1;
|
||||||
fpriv->authenticated = 1;
|
fpriv->authenticated = 1;
|
||||||
|
|
||||||
|
ret = drm_set_master(dev, fpriv, true);
|
||||||
|
if (ret)
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
if (old_master)
|
if (old_master)
|
||||||
drm_master_put(&old_master);
|
drm_master_put(&old_master);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_err:
|
out_err:
|
||||||
/* drop both references and restore old master on failure */
|
/* drop references and restore old master on failure */
|
||||||
drm_master_put(&dev->master);
|
|
||||||
drm_master_put(&fpriv->master);
|
drm_master_put(&fpriv->master);
|
||||||
fpriv->master = old_master;
|
fpriv->master = old_master;
|
||||||
|
|
||||||
|
@ -188,21 +201,21 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->master = drm_master_get(file_priv->master);
|
ret = drm_set_master(dev, file_priv, false);
|
||||||
file_priv->is_master = 1;
|
|
||||||
if (dev->driver->master_set) {
|
|
||||||
ret = dev->driver->master_set(dev, file_priv, false);
|
|
||||||
if (unlikely(ret != 0)) {
|
|
||||||
file_priv->is_master = 0;
|
|
||||||
drm_master_put(&dev->master);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&dev->master_mutex);
|
mutex_unlock(&dev->master_mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void drm_drop_master(struct drm_device *dev,
|
||||||
|
struct drm_file *fpriv)
|
||||||
|
{
|
||||||
|
if (dev->driver->master_drop)
|
||||||
|
dev->driver->master_drop(dev, fpriv);
|
||||||
|
drm_master_put(&dev->master);
|
||||||
|
fpriv->is_master = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
|
int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
|
||||||
struct drm_file *file_priv)
|
struct drm_file *file_priv)
|
||||||
{
|
{
|
||||||
|
@ -216,11 +229,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (dev->driver->master_drop)
|
drm_drop_master(dev, file_priv);
|
||||||
dev->driver->master_drop(dev, file_priv, false);
|
|
||||||
drm_master_put(&dev->master);
|
|
||||||
file_priv->is_master = 0;
|
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&dev->master_mutex);
|
mutex_unlock(&dev->master_mutex);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -271,17 +280,12 @@ void drm_master_release(struct drm_file *file_priv)
|
||||||
mutex_unlock(&dev->struct_mutex);
|
mutex_unlock(&dev->struct_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev->master == file_priv->master) {
|
if (dev->master == file_priv->master)
|
||||||
/* drop the reference held my the minor */
|
drm_drop_master(dev, file_priv);
|
||||||
if (dev->driver->master_drop)
|
|
||||||
dev->driver->master_drop(dev, file_priv, true);
|
|
||||||
drm_master_put(&dev->master);
|
|
||||||
}
|
|
||||||
out:
|
out:
|
||||||
/* drop the master reference held by the file priv */
|
/* drop the master reference held by the file priv */
|
||||||
if (file_priv->master)
|
if (file_priv->master)
|
||||||
drm_master_put(&file_priv->master);
|
drm_master_put(&file_priv->master);
|
||||||
file_priv->is_master = 0;
|
|
||||||
mutex_unlock(&dev->master_mutex);
|
mutex_unlock(&dev->master_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1228,8 +1228,7 @@ static int vmw_master_set(struct drm_device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmw_master_drop(struct drm_device *dev,
|
static void vmw_master_drop(struct drm_device *dev,
|
||||||
struct drm_file *file_priv,
|
struct drm_file *file_priv)
|
||||||
bool from_release)
|
|
||||||
{
|
{
|
||||||
struct vmw_private *dev_priv = vmw_priv(dev);
|
struct vmw_private *dev_priv = vmw_priv(dev);
|
||||||
struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
|
struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
|
||||||
|
|
|
@ -573,8 +573,7 @@ struct drm_driver {
|
||||||
|
|
||||||
int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
|
int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
|
||||||
bool from_open);
|
bool from_open);
|
||||||
void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
|
void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
|
||||||
bool from_release);
|
|
||||||
|
|
||||||
int (*debugfs_init)(struct drm_minor *minor);
|
int (*debugfs_init)(struct drm_minor *minor);
|
||||||
void (*debugfs_cleanup)(struct drm_minor *minor);
|
void (*debugfs_cleanup)(struct drm_minor *minor);
|
||||||
|
|
Loading…
Reference in New Issue