mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-19 18:24:14 +08:00
drm: drop redundant drm_file->is_master
The drm_file->is_master field is redundant as it's equivalent to: drm_file->master && drm_file->master == drm_file->minor->master 1) "=>" Whenever we set drm_file->is_master, we also set: drm_file->minor->master = drm_file->master; Whenever we clear drm_file->is_master, we also call: drm_master_put(&drm_file->minor->master); which implicitly clears it to NULL. 2) "<=" minor->master cannot be set if it is non-NULL. Therefore, it stays as is unless a file drops it. If minor->master is NULL, it is only set by places that also adjust drm_file->is_master. Therefore, we can safely drop is_master and replace it by an inline helper that matches: drm_file->master && drm_file->master == drm_file->minor->master Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
parent
9f8d21ea27
commit
48ba813701
@ -3243,7 +3243,7 @@ int drm_mode_getfb(struct drm_device *dev,
|
||||
r->bpp = fb->bits_per_pixel;
|
||||
r->pitch = fb->pitches[0];
|
||||
if (fb->funcs->create_handle) {
|
||||
if (file_priv->is_master || capable(CAP_SYS_ADMIN) ||
|
||||
if (drm_is_master(file_priv) || capable(CAP_SYS_ADMIN) ||
|
||||
drm_is_control_client(file_priv)) {
|
||||
ret = fb->funcs->create_handle(fb, file_priv,
|
||||
&r->handle);
|
||||
|
@ -307,7 +307,7 @@ static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
|
||||
return -EACCES;
|
||||
|
||||
/* MASTER is only for master or control clients */
|
||||
if (unlikely((flags & DRM_MASTER) && !file_priv->is_master &&
|
||||
if (unlikely((flags & DRM_MASTER) && !drm_is_master(file_priv) &&
|
||||
!drm_is_control_client(file_priv)))
|
||||
return -EACCES;
|
||||
|
||||
|
@ -233,7 +233,6 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
priv->is_master = 1;
|
||||
/* take another reference for the copy in the local file priv */
|
||||
priv->master = drm_master_get(priv->minor->master);
|
||||
priv->authenticated = 1;
|
||||
@ -461,7 +460,7 @@ int drm_release(struct inode *inode, struct file *filp)
|
||||
|
||||
mutex_lock(&dev->master_mutex);
|
||||
|
||||
if (file_priv->is_master) {
|
||||
if (drm_is_master(file_priv)) {
|
||||
struct drm_master *master = file_priv->master;
|
||||
struct drm_file *temp;
|
||||
|
||||
@ -497,7 +496,6 @@ int drm_release(struct inode *inode, struct file *filp)
|
||||
/* drop the master reference held by the file priv */
|
||||
if (file_priv->master)
|
||||
drm_master_put(&file_priv->master);
|
||||
file_priv->is_master = 0;
|
||||
mutex_unlock(&dev->master_mutex);
|
||||
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
|
@ -111,7 +111,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
|
||||
/* don't set the block all signals on the master process for now
|
||||
* really probably not the correct answer but lets us debug xkb
|
||||
* xserver for now */
|
||||
if (!file_priv->is_master) {
|
||||
if (!drm_is_master(file_priv)) {
|
||||
sigemptyset(&dev->sigmask);
|
||||
sigaddset(&dev->sigmask, SIGSTOP);
|
||||
sigaddset(&dev->sigmask, SIGTSTP);
|
||||
|
@ -177,7 +177,7 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&dev->master_mutex);
|
||||
if (file_priv->is_master)
|
||||
if (drm_is_master(file_priv))
|
||||
goto out_unlock;
|
||||
|
||||
if (file_priv->minor->master) {
|
||||
@ -191,13 +191,10 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
|
||||
}
|
||||
|
||||
file_priv->minor->master = drm_master_get(file_priv->master);
|
||||
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;
|
||||
if (unlikely(ret != 0))
|
||||
drm_master_put(&file_priv->minor->master);
|
||||
}
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
@ -211,7 +208,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
|
||||
int ret = -EINVAL;
|
||||
|
||||
mutex_lock(&dev->master_mutex);
|
||||
if (!file_priv->is_master)
|
||||
if (!drm_is_master(file_priv))
|
||||
goto out_unlock;
|
||||
|
||||
if (!file_priv->minor->master)
|
||||
@ -221,7 +218,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
|
||||
if (dev->driver->master_drop)
|
||||
dev->driver->master_drop(dev, file_priv, false);
|
||||
drm_master_put(&file_priv->minor->master);
|
||||
file_priv->is_master = 0;
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&dev->master_mutex);
|
||||
|
@ -1260,7 +1260,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
|
||||
|
||||
flags = 0;
|
||||
if (args->flags & I915_EXEC_SECURE) {
|
||||
if (!file->is_master || !capable(CAP_SYS_ADMIN))
|
||||
if (!drm_is_master(file) || !capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
flags |= I915_DISPATCH_SECURE;
|
||||
@ -1369,7 +1369,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
|
||||
ret = i915_parse_cmds(ring,
|
||||
batch_obj,
|
||||
args->batch_start_offset,
|
||||
file->is_master);
|
||||
drm_is_master(file));
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
|
@ -990,7 +990,7 @@ static struct vmw_master *vmw_master_check(struct drm_device *dev,
|
||||
if (unlikely(ret != 0))
|
||||
return ERR_PTR(-ERESTARTSYS);
|
||||
|
||||
if (file_priv->is_master) {
|
||||
if (drm_is_master(file_priv)) {
|
||||
mutex_unlock(&dev->master_mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ static void imx_drm_driver_preclose(struct drm_device *drm,
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!file->is_master)
|
||||
if (!drm_is_master(file))
|
||||
return;
|
||||
|
||||
for (i = 0; i < MAX_CRTC; i++)
|
||||
|
@ -387,8 +387,6 @@ struct drm_prime_file_private {
|
||||
struct drm_file {
|
||||
unsigned always_authenticated :1;
|
||||
unsigned authenticated :1;
|
||||
/* Whether we're master for a minor. Protected by master_mutex */
|
||||
unsigned is_master :1;
|
||||
/* true when the client has asked us to expose stereo 3D mode flags */
|
||||
unsigned stereo_allowed :1;
|
||||
/*
|
||||
@ -1034,7 +1032,7 @@ struct drm_device {
|
||||
/** \name Locks */
|
||||
/*@{ */
|
||||
struct mutex struct_mutex; /**< For others */
|
||||
struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
|
||||
struct mutex master_mutex; /**< For drm_minor::master */
|
||||
/*@} */
|
||||
|
||||
/** \name Usage Counters */
|
||||
@ -1172,6 +1170,21 @@ static inline bool drm_is_primary_client(const struct drm_file *file_priv)
|
||||
return file_priv->minor->type == DRM_MINOR_LEGACY;
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_is_master() - Check whether a DRM open-file is DRM-Master
|
||||
* @file: DRM open-file context
|
||||
*
|
||||
* This checks whether a DRM open-file context is owner of the master context
|
||||
* attached to it. If a file owns a master context, it's called DRM-Master.
|
||||
* Per DRM device, only one such file can be DRM-Master at a time.
|
||||
*
|
||||
* Returns: True if the file is DRM-Master, otherwise false.
|
||||
*/
|
||||
static inline bool drm_is_master(const struct drm_file *file)
|
||||
{
|
||||
return file->master && file->master == file->minor->master;
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
/** \name Internal function definitions */
|
||||
/*@{*/
|
||||
|
Loading…
Reference in New Issue
Block a user