Commit f4aede2e authored by David Herrmann's avatar David Herrmann

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: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 45e212d2
...@@ -44,7 +44,7 @@ DEFINE_MUTEX(drm_global_mutex); ...@@ -44,7 +44,7 @@ DEFINE_MUTEX(drm_global_mutex);
EXPORT_SYMBOL(drm_global_mutex); EXPORT_SYMBOL(drm_global_mutex);
static int drm_open_helper(struct inode *inode, struct file *filp, 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) static int drm_setup(struct drm_device * dev)
{ {
...@@ -110,7 +110,7 @@ int drm_open(struct inode *inode, struct file *filp) ...@@ -110,7 +110,7 @@ int drm_open(struct inode *inode, struct file *filp)
filp->f_mapping = dev->dev_mapping; filp->f_mapping = dev->dev_mapping;
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
retcode = drm_open_helper(inode, filp, dev); retcode = drm_open_helper(inode, filp, minor);
if (retcode) if (retcode)
goto err_undo; goto err_undo;
if (need_setup) { if (need_setup) {
...@@ -196,16 +196,16 @@ static int drm_cpu_valid(void) ...@@ -196,16 +196,16 @@ static int drm_cpu_valid(void)
* *
* \param inode device inode. * \param inode device inode.
* \param filp file pointer. * \param filp file pointer.
* \param dev device. * \param minor acquired minor-object.
* \return zero on success or a negative number on failure. * \return zero on success or a negative number on failure.
* *
* Creates and initializes a drm_file structure for the file private data in \p * 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. * filp and add it into the double linked list in \p dev.
*/ */
static int drm_open_helper(struct inode *inode, struct file *filp, 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; struct drm_file *priv;
int ret; int ret;
...@@ -216,7 +216,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp, ...@@ -216,7 +216,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) if (dev->switch_power_state != DRM_SWITCH_POWER_ON && dev->switch_power_state != DRM_SWITCH_POWER_DYNAMIC_OFF)
return -EINVAL; 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); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
...@@ -226,11 +226,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp, ...@@ -226,11 +226,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
priv->filp = filp; priv->filp = filp;
priv->uid = current_euid(); priv->uid = current_euid();
priv->pid = get_pid(task_pid(current)); priv->pid = get_pid(task_pid(current));
priv->minor = idr_find(&drm_minors_idr, minor_id); priv->minor = minor;
if (!priv->minor) {
ret = -ENODEV;
goto out_put_pid;
}
/* for compatibility root is always authenticated */ /* for compatibility root is always authenticated */
priv->always_authenticated = capable(CAP_SYS_ADMIN); priv->always_authenticated = capable(CAP_SYS_ADMIN);
...@@ -336,7 +332,6 @@ static int drm_open_helper(struct inode *inode, struct file *filp, ...@@ -336,7 +332,6 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
drm_prime_destroy_file_private(&priv->prime); drm_prime_destroy_file_private(&priv->prime);
if (dev->driver->driver_features & DRIVER_GEM) if (dev->driver->driver_features & DRIVER_GEM)
drm_gem_release(dev, priv); drm_gem_release(dev, priv);
out_put_pid:
put_pid(priv->pid); put_pid(priv->pid);
kfree(priv); kfree(priv);
filp->private_data = NULL; filp->private_data = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment