Skip to content

Commit f4aede2

Browse files
author
David Herrmann
committed
drm: skip redundant minor-lookup in open path
The drm_open_helper() function is only used internally for drm_open() so we can safely pass in the minor-object directly instead of the minor-id. This way, we avoid the additional minor IDR lookup, which we already do twice in drm_stub_open() and drm_open(). Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 45e212d commit f4aede2

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

‎drivers/gpu/drm/drm_fops.c‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ DEFINE_MUTEX(drm_global_mutex);
4444
EXPORT_SYMBOL(drm_global_mutex);
4545

4646
static int drm_open_helper(struct inode *inode, struct file *filp,
47-
struct drm_device * dev);
47+
struct drm_minor *minor);
4848

4949
static int drm_setup(struct drm_device * dev)
5050
{
@@ -110,7 +110,7 @@ int drm_open(struct inode *inode, struct file *filp)
110110
filp->f_mapping = dev->dev_mapping;
111111
mutex_unlock(&dev->struct_mutex);
112112

113-
retcode = drm_open_helper(inode, filp, dev);
113+
retcode = drm_open_helper(inode, filp, minor);
114114
if (retcode)
115115
goto err_undo;
116116
if (need_setup) {
@@ -196,16 +196,16 @@ static int drm_cpu_valid(void)
196196
*
197197
* \param inode device inode.
198198
* \param filp file pointer.
199-
* \param dev device.
199+
* \param minor acquired minor-object.
200200
* \return zero on success or a negative number on failure.
201201
*
202202
* Creates and initializes a drm_file structure for the file private data in \p
203203
* filp and add it into the double linked list in \p dev.
204204
*/
205205
static int drm_open_helper(struct inode *inode, struct file *filp,
206-
struct drm_device * dev)
206+
struct drm_minor *minor)
207207
{
208-
int minor_id = iminor(inode);
208+
struct drm_device *dev = minor->dev;
209209
struct drm_file *priv;
210210
int ret;
211211

@@ -216,7 +216,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
216216
if (dev->switch_power_state != DRM_SWITCH_POWER_ON && dev->switch_power_state != DRM_SWITCH_POWER_DYNAMIC_OFF)
217217
return -EINVAL;
218218

219-
DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor_id);
219+
DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor->index);
220220

221221
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
222222
if (!priv)
@@ -226,11 +226,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
226226
priv->filp = filp;
227227
priv->uid = current_euid();
228228
priv->pid = get_pid(task_pid(current));
229-
priv->minor = idr_find(&drm_minors_idr, minor_id);
230-
if (!priv->minor) {
231-
ret = -ENODEV;
232-
goto out_put_pid;
233-
}
229+
priv->minor = minor;
234230

235231
/* for compatibility root is always authenticated */
236232
priv->always_authenticated = capable(CAP_SYS_ADMIN);
@@ -336,7 +332,6 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
336332
drm_prime_destroy_file_private(&priv->prime);
337333
if (dev->driver->driver_features & DRIVER_GEM)
338334
drm_gem_release(dev, priv);
339-
out_put_pid:
340335
put_pid(priv->pid);
341336
kfree(priv);
342337
filp->private_data = NULL;

0 commit comments

Comments
 (0)