aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-07-22 12:46:09 -0400
committerDavid Herrmann <dh.herrmann@gmail.com>2014-08-05 10:07:50 -0400
commit48ba813701eb14b3008edefef4a0789b328e278c (patch)
treecab45fc97db3eb800338196add945c6f47643cee
parent9f8d21ea276177547725a60cefc1b6da742f14d3 (diff)
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>
-rw-r--r--drivers/gpu/drm/drm_crtc.c2
-rw-r--r--drivers/gpu/drm/drm_drv.c2
-rw-r--r--drivers/gpu/drm/drm_fops.c4
-rw-r--r--drivers/gpu/drm/drm_lock.c2
-rw-r--r--drivers/gpu/drm/drm_stub.c10
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c4
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c2
-rw-r--r--drivers/staging/imx-drm/imx-drm-core.c2
-rw-r--r--include/drm/drmP.h19
9 files changed, 27 insertions, 20 deletions
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 3c4a62169f28..670b5eb13c87 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -3243,7 +3243,7 @@ int drm_mode_getfb(struct drm_device *dev,
3243 r->bpp = fb->bits_per_pixel; 3243 r->bpp = fb->bits_per_pixel;
3244 r->pitch = fb->pitches[0]; 3244 r->pitch = fb->pitches[0];
3245 if (fb->funcs->create_handle) { 3245 if (fb->funcs->create_handle) {
3246 if (file_priv->is_master || capable(CAP_SYS_ADMIN) || 3246 if (drm_is_master(file_priv) || capable(CAP_SYS_ADMIN) ||
3247 drm_is_control_client(file_priv)) { 3247 drm_is_control_client(file_priv)) {
3248 ret = fb->funcs->create_handle(fb, file_priv, 3248 ret = fb->funcs->create_handle(fb, file_priv,
3249 &r->handle); 3249 &r->handle);
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 0cc182745e31..7aa8121d1323 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -307,7 +307,7 @@ static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
307 return -EACCES; 307 return -EACCES;
308 308
309 /* MASTER is only for master or control clients */ 309 /* MASTER is only for master or control clients */
310 if (unlikely((flags & DRM_MASTER) && !file_priv->is_master && 310 if (unlikely((flags & DRM_MASTER) && !drm_is_master(file_priv) &&
311 !drm_is_control_client(file_priv))) 311 !drm_is_control_client(file_priv)))
312 return -EACCES; 312 return -EACCES;
313 313
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 55143f7747f3..53435e07fa8d 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -233,7 +233,6 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
233 goto out_close; 233 goto out_close;
234 } 234 }
235 235
236 priv->is_master = 1;
237 /* take another reference for the copy in the local file priv */ 236 /* take another reference for the copy in the local file priv */
238 priv->master = drm_master_get(priv->minor->master); 237 priv->master = drm_master_get(priv->minor->master);
239 priv->authenticated = 1; 238 priv->authenticated = 1;
@@ -461,7 +460,7 @@ int drm_release(struct inode *inode, struct file *filp)
461 460
462 mutex_lock(&dev->master_mutex); 461 mutex_lock(&dev->master_mutex);
463 462
464 if (file_priv->is_master) { 463 if (drm_is_master(file_priv)) {
465 struct drm_master *master = file_priv->master; 464 struct drm_master *master = file_priv->master;
466 struct drm_file *temp; 465 struct drm_file *temp;
467 466
@@ -497,7 +496,6 @@ int drm_release(struct inode *inode, struct file *filp)
497 /* drop the master reference held by the file priv */ 496 /* drop the master reference held by the file priv */
498 if (file_priv->master) 497 if (file_priv->master)
499 drm_master_put(&file_priv->master); 498 drm_master_put(&file_priv->master);
500 file_priv->is_master = 0;
501 mutex_unlock(&dev->master_mutex); 499 mutex_unlock(&dev->master_mutex);
502 500
503 mutex_lock(&dev->struct_mutex); 501 mutex_lock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
index f6452682141b..786401cd5f60 100644
--- a/drivers/gpu/drm/drm_lock.c
+++ b/drivers/gpu/drm/drm_lock.c
@@ -111,7 +111,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
111 /* don't set the block all signals on the master process for now 111 /* don't set the block all signals on the master process for now
112 * really probably not the correct answer but lets us debug xkb 112 * really probably not the correct answer but lets us debug xkb
113 * xserver for now */ 113 * xserver for now */
114 if (!file_priv->is_master) { 114 if (!drm_is_master(file_priv)) {
115 sigemptyset(&dev->sigmask); 115 sigemptyset(&dev->sigmask);
116 sigaddset(&dev->sigmask, SIGSTOP); 116 sigaddset(&dev->sigmask, SIGSTOP);
117 sigaddset(&dev->sigmask, SIGTSTP); 117 sigaddset(&dev->sigmask, SIGTSTP);
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 233ea208c9fe..18c9b3d8201e 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -177,7 +177,7 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
177 int ret = 0; 177 int ret = 0;
178 178
179 mutex_lock(&dev->master_mutex); 179 mutex_lock(&dev->master_mutex);
180 if (file_priv->is_master) 180 if (drm_is_master(file_priv))
181 goto out_unlock; 181 goto out_unlock;
182 182
183 if (file_priv->minor->master) { 183 if (file_priv->minor->master) {
@@ -191,13 +191,10 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
191 } 191 }
192 192
193 file_priv->minor->master = drm_master_get(file_priv->master); 193 file_priv->minor->master = drm_master_get(file_priv->master);
194 file_priv->is_master = 1;
195 if (dev->driver->master_set) { 194 if (dev->driver->master_set) {
196 ret = dev->driver->master_set(dev, file_priv, false); 195 ret = dev->driver->master_set(dev, file_priv, false);
197 if (unlikely(ret != 0)) { 196 if (unlikely(ret != 0))
198 file_priv->is_master = 0;
199 drm_master_put(&file_priv->minor->master); 197 drm_master_put(&file_priv->minor->master);
200 }
201 } 198 }
202 199
203out_unlock: 200out_unlock:
@@ -211,7 +208,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
211 int ret = -EINVAL; 208 int ret = -EINVAL;
212 209
213 mutex_lock(&dev->master_mutex); 210 mutex_lock(&dev->master_mutex);
214 if (!file_priv->is_master) 211 if (!drm_is_master(file_priv))
215 goto out_unlock; 212 goto out_unlock;
216 213
217 if (!file_priv->minor->master) 214 if (!file_priv->minor->master)
@@ -221,7 +218,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
221 if (dev->driver->master_drop) 218 if (dev->driver->master_drop)
222 dev->driver->master_drop(dev, file_priv, false); 219 dev->driver->master_drop(dev, file_priv, false);
223 drm_master_put(&file_priv->minor->master); 220 drm_master_put(&file_priv->minor->master);
224 file_priv->is_master = 0;
225 221
226out_unlock: 222out_unlock:
227 mutex_unlock(&dev->master_mutex); 223 mutex_unlock(&dev->master_mutex);
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 60998fc4e5b2..2dd19da6b4b3 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -1260,7 +1260,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
1260 1260
1261 flags = 0; 1261 flags = 0;
1262 if (args->flags & I915_EXEC_SECURE) { 1262 if (args->flags & I915_EXEC_SECURE) {
1263 if (!file->is_master || !capable(CAP_SYS_ADMIN)) 1263 if (!drm_is_master(file) || !capable(CAP_SYS_ADMIN))
1264 return -EPERM; 1264 return -EPERM;
1265 1265
1266 flags |= I915_DISPATCH_SECURE; 1266 flags |= I915_DISPATCH_SECURE;
@@ -1369,7 +1369,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
1369 ret = i915_parse_cmds(ring, 1369 ret = i915_parse_cmds(ring,
1370 batch_obj, 1370 batch_obj,
1371 args->batch_start_offset, 1371 args->batch_start_offset,
1372 file->is_master); 1372 drm_is_master(file));
1373 if (ret) 1373 if (ret)
1374 goto err; 1374 goto err;
1375 1375
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 18b54acacfbb..63c4d6f0281e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -990,7 +990,7 @@ static struct vmw_master *vmw_master_check(struct drm_device *dev,
990 if (unlikely(ret != 0)) 990 if (unlikely(ret != 0))
991 return ERR_PTR(-ERESTARTSYS); 991 return ERR_PTR(-ERESTARTSYS);
992 992
993 if (file_priv->is_master) { 993 if (drm_is_master(file_priv)) {
994 mutex_unlock(&dev->master_mutex); 994 mutex_unlock(&dev->master_mutex);
995 return NULL; 995 return NULL;
996 } 996 }
diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
index 6f54ff4f9372..72913b299047 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -182,7 +182,7 @@ static void imx_drm_driver_preclose(struct drm_device *drm,
182{ 182{
183 int i; 183 int i;
184 184
185 if (!file->is_master) 185 if (!drm_is_master(file))
186 return; 186 return;
187 187
188 for (i = 0; i < MAX_CRTC; i++) 188 for (i = 0; i < MAX_CRTC; i++)
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 80889982d196..6ede53712d7b 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -387,8 +387,6 @@ struct drm_prime_file_private {
387struct drm_file { 387struct drm_file {
388 unsigned always_authenticated :1; 388 unsigned always_authenticated :1;
389 unsigned authenticated :1; 389 unsigned authenticated :1;
390 /* Whether we're master for a minor. Protected by master_mutex */
391 unsigned is_master :1;
392 /* true when the client has asked us to expose stereo 3D mode flags */ 390 /* true when the client has asked us to expose stereo 3D mode flags */
393 unsigned stereo_allowed :1; 391 unsigned stereo_allowed :1;
394 /* 392 /*
@@ -1034,7 +1032,7 @@ struct drm_device {
1034 /** \name Locks */ 1032 /** \name Locks */
1035 /*@{ */ 1033 /*@{ */
1036 struct mutex struct_mutex; /**< For others */ 1034 struct mutex struct_mutex; /**< For others */
1037 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */ 1035 struct mutex master_mutex; /**< For drm_minor::master */
1038 /*@} */ 1036 /*@} */
1039 1037
1040 /** \name Usage Counters */ 1038 /** \name Usage Counters */
@@ -1172,6 +1170,21 @@ static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1172 return file_priv->minor->type == DRM_MINOR_LEGACY; 1170 return file_priv->minor->type == DRM_MINOR_LEGACY;
1173} 1171}
1174 1172
1173/**
1174 * drm_is_master() - Check whether a DRM open-file is DRM-Master
1175 * @file: DRM open-file context
1176 *
1177 * This checks whether a DRM open-file context is owner of the master context
1178 * attached to it. If a file owns a master context, it's called DRM-Master.
1179 * Per DRM device, only one such file can be DRM-Master at a time.
1180 *
1181 * Returns: True if the file is DRM-Master, otherwise false.
1182 */
1183static inline bool drm_is_master(const struct drm_file *file)
1184{
1185 return file->master && file->master == file->minor->master;
1186}
1187
1175/******************************************************************/ 1188/******************************************************************/
1176/** \name Internal function definitions */ 1189/** \name Internal function definitions */
1177/*@{*/ 1190/*@{*/