Skip to content

Commit 48ba813

Browse files
author
David Herrmann
committed
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>
1 parent 9f8d21e commit 48ba813

9 files changed

Lines changed: 27 additions & 20 deletions

File tree

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,7 @@ int drm_mode_getfb(struct drm_device *dev,
32433243
r->bpp = fb->bits_per_pixel;
32443244
r->pitch = fb->pitches[0];
32453245
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) ||
32473247
drm_is_control_client(file_priv)) {
32483248
ret = fb->funcs->create_handle(fb, file_priv,
32493249
&r->handle);

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
307307
return -EACCES;
308308

309309
/* 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) &&
311311
!drm_is_control_client(file_priv)))
312312
return -EACCES;
313313

‎drivers/gpu/drm/drm_fops.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
233233
goto out_close;
234234
}
235235

236-
priv->is_master = 1;
237236
/* take another reference for the copy in the local file priv */
238237
priv->master = drm_master_get(priv->minor->master);
239238
priv->authenticated = 1;
@@ -461,7 +460,7 @@ int drm_release(struct inode *inode, struct file *filp)
461460

462461
mutex_lock(&dev->master_mutex);
463462

464-
if (file_priv->is_master) {
463+
if (drm_is_master(file_priv)) {
465464
struct drm_master *master = file_priv->master;
466465
struct drm_file *temp;
467466

@@ -497,7 +496,6 @@ int drm_release(struct inode *inode, struct file *filp)
497496
/* drop the master reference held by the file priv */
498497
if (file_priv->master)
499498
drm_master_put(&file_priv->master);
500-
file_priv->is_master = 0;
501499
mutex_unlock(&dev->master_mutex);
502500

503501
mutex_lock(&dev->struct_mutex);

‎drivers/gpu/drm/drm_lock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
111111
/* don't set the block all signals on the master process for now
112112
* really probably not the correct answer but lets us debug xkb
113113
* xserver for now */
114-
if (!file_priv->is_master) {
114+
if (!drm_is_master(file_priv)) {
115115
sigemptyset(&dev->sigmask);
116116
sigaddset(&dev->sigmask, SIGSTOP);
117117
sigaddset(&dev->sigmask, SIGTSTP);

‎drivers/gpu/drm/drm_stub.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
177177
int ret = 0;
178178

179179
mutex_lock(&dev->master_mutex);
180-
if (file_priv->is_master)
180+
if (drm_is_master(file_priv))
181181
goto out_unlock;
182182

183183
if (file_priv->minor->master) {
@@ -191,13 +191,10 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
191191
}
192192

193193
file_priv->minor->master = drm_master_get(file_priv->master);
194-
file_priv->is_master = 1;
195194
if (dev->driver->master_set) {
196195
ret = dev->driver->master_set(dev, file_priv, false);
197-
if (unlikely(ret != 0)) {
198-
file_priv->is_master = 0;
196+
if (unlikely(ret != 0))
199197
drm_master_put(&file_priv->minor->master);
200-
}
201198
}
202199

203200
out_unlock:
@@ -211,7 +208,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
211208
int ret = -EINVAL;
212209

213210
mutex_lock(&dev->master_mutex);
214-
if (!file_priv->is_master)
211+
if (!drm_is_master(file_priv))
215212
goto out_unlock;
216213

217214
if (!file_priv->minor->master)
@@ -221,7 +218,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
221218
if (dev->driver->master_drop)
222219
dev->driver->master_drop(dev, file_priv, false);
223220
drm_master_put(&file_priv->minor->master);
224-
file_priv->is_master = 0;
225221

226222
out_unlock:
227223
mutex_unlock(&dev->master_mutex);

‎drivers/gpu/drm/i915/i915_gem_execbuffer.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
12601260

12611261
flags = 0;
12621262
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))
12641264
return -EPERM;
12651265

12661266
flags |= I915_DISPATCH_SECURE;
@@ -1369,7 +1369,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
13691369
ret = i915_parse_cmds(ring,
13701370
batch_obj,
13711371
args->batch_start_offset,
1372-
file->is_master);
1372+
drm_is_master(file));
13731373
if (ret)
13741374
goto err;
13751375

‎drivers/gpu/drm/vmwgfx/vmwgfx_drv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ static struct vmw_master *vmw_master_check(struct drm_device *dev,
990990
if (unlikely(ret != 0))
991991
return ERR_PTR(-ERESTARTSYS);
992992

993-
if (file_priv->is_master) {
993+
if (drm_is_master(file_priv)) {
994994
mutex_unlock(&dev->master_mutex);
995995
return NULL;
996996
}

‎drivers/staging/imx-drm/imx-drm-core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static void imx_drm_driver_preclose(struct drm_device *drm,
182182
{
183183
int i;
184184

185-
if (!file->is_master)
185+
if (!drm_is_master(file))
186186
return;
187187

188188
for (i = 0; i < MAX_CRTC; i++)

‎include/drm/drmP.h‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ struct drm_prime_file_private {
387387
struct drm_file {
388388
unsigned always_authenticated :1;
389389
unsigned authenticated :1;
390-
/* Whether we're master for a minor. Protected by master_mutex */
391-
unsigned is_master :1;
392390
/* true when the client has asked us to expose stereo 3D mode flags */
393391
unsigned stereo_allowed :1;
394392
/*
@@ -1034,7 +1032,7 @@ struct drm_device {
10341032
/** \name Locks */
10351033
/*@{ */
10361034
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 */
10381036
/*@} */
10391037

10401038
/** \name Usage Counters */
@@ -1172,6 +1170,21 @@ static inline bool drm_is_primary_client(const struct drm_file *file_priv)
11721170
return file_priv->minor->type == DRM_MINOR_LEGACY;
11731171
}
11741172

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+
*/
1183+
static inline bool drm_is_master(const struct drm_file *file)
1184+
{
1185+
return file->master && file->master == file->minor->master;
1186+
}
1187+
11751188
/******************************************************************/
11761189
/** \name Internal function definitions */
11771190
/*@{*/

0 commit comments

Comments
 (0)