drm: skip redundant minor-lookup in open path
authorDavid Herrmann <dh.herrmann@gmail.com>
Wed, 29 Jan 2014 09:18:02 +0000 (10:18 +0100)
committerSimon Horman <horms+renesas@verge.net.au>
Thu, 11 Dec 2014 01:21:31 +0000 (10:21 +0900)
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>
(cherry picked from commit f4aede2e3291896e7cb42755ecc5b6815b6cac97)
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
drivers/gpu/drm/drm_fops.c

index 88ebc2b..1ec4498 100644 (file)
@@ -44,7 +44,7 @@ DEFINE_MUTEX(drm_global_mutex);
 EXPORT_SYMBOL(drm_global_mutex);
 
 static int drm_open_helper(struct inode *inode, struct file *filp,
-                          struct drm_device * dev);
+                          struct drm_minor *minor);
 
 static int drm_setup(struct drm_device * dev)
 {
@@ -100,7 +100,7 @@ int drm_open(struct inode *inode, struct file *filp)
        /* share address_space across all char-devs of a single device */
        filp->f_mapping = dev->anon_inode->i_mapping;
 
-       retcode = drm_open_helper(inode, filp, dev);
+       retcode = drm_open_helper(inode, filp, minor);
        if (retcode)
                goto err_undo;
        if (need_setup) {
@@ -182,16 +182,16 @@ static int drm_cpu_valid(void)
  *
  * \param inode device inode.
  * \param filp file pointer.
- * \param dev device.
+ * \param minor acquired minor-object.
  * \return zero on success or a negative number on failure.
  *
  * Creates and initializes a drm_file structure for the file private data in \p
  * filp and add it into the double linked list in \p dev.
  */
 static int drm_open_helper(struct inode *inode, struct file *filp,
-                          struct drm_device * dev)
+                          struct drm_minor *minor)
 {
-       int minor_id = iminor(inode);
+       struct drm_device *dev = minor->dev;
        struct drm_file *priv;
        int ret;
 
@@ -202,7 +202,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
        if (dev->switch_power_state != DRM_SWITCH_POWER_ON && dev->switch_power_state != DRM_SWITCH_POWER_DYNAMIC_OFF)
                return -EINVAL;
 
-       DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor_id);
+       DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor->index);
 
        priv = kzalloc(sizeof(*priv), GFP_KERNEL);
        if (!priv)
@@ -212,11 +212,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
        priv->filp = filp;
        priv->uid = current_euid();
        priv->pid = get_pid(task_pid(current));
-       priv->minor = idr_find(&drm_minors_idr, minor_id);
-       if (!priv->minor) {
-               ret = -ENODEV;
-               goto out_put_pid;
-       }
+       priv->minor = minor;
 
        /* for compatibility root is always authenticated */
        priv->always_authenticated = capable(CAP_SYS_ADMIN);
@@ -322,7 +318,6 @@ out_prime_destroy:
                drm_prime_destroy_file_private(&priv->prime);
        if (dev->driver->driver_features & DRIVER_GEM)
                drm_gem_release(dev, priv);
-out_put_pid:
        put_pid(priv->pid);
        kfree(priv);
        filp->private_data = NULL;